リストではなくIPの範囲を検索する

リストではなくIPの範囲を検索する

IP のリストをファイルで調べる代わりに、範囲を調べたいと思っています。範囲はクラス C と同じ大きさにする必要があります。これを実現するために、以下のコードを編集するのを手伝ってくれる人はいませんか? サブネット マスク 255.255.0.0 で 10.0.0.0 を検索しようとしています。

' NetworkFindInfo.vbs - Windows Logon Script.
' VBScript - Look up a computers info. 
' Author Chris Collins
' Version 1 - July 2018
' ----------------------------------------------------------' 

Option Explicit

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Const PATH_TO_INPUT = "C:\Users\ccollins\Desktop\NetworkFindingInfo\ComputerList.txt"
Const PATH_TO_OUTPUT = "C:\Users\ccollins\Desktop\NetworkFindingInfo\ComputerInfo.csv"

Dim fso
Set fso = WScript.CreateObject("Scripting.FileSystemObject")

Dim shl
Set shl = WScript.CreateObject("WScript.Shell")

Dim input
Set input = fso.OpenTextFile(PATH_TO_INPUT)

Dim output
Set output = fso.CreateTextFile(PATH_TO_OUTPUT, True)

output.WriteLine "Hostname,Computer Name,Domain,Serial Number,Make,Model,BIOS Version,Operating System,CPU,Memory (MB),Disk Drives,MAC Address"

Dim wmiService
Dim wmiResults

Dim hostname
Dim computername
Dim domain
Dim make
Dim model
Dim biosversion
Dim operatingSystem
Dim serialNumber
Dim cpu
Dim memory
Dim drives
Dim mac

Dim line
Dim exec
Dim pingResults
While Not input.AtEndOfStream
line = input.ReadLine
hostname = ""
computername = ""
domain = ""
make = ""
model = ""
biosversion = ""
operatingSystem = ""
serialNumber = ""
cpu = ""
memory = ""
drives = ""
mac = ""

Set exec = shl.Exec("ping -n 2 -w 1000 " & line)
pingResults = LCase(exec.StdOut.ReadAll)

If InStr(pingResults, "reply from") Then
On Error Resume Next

Set wmiService = GetObject("winmgmts:\\" & line & "\root\CIMV2")

If Not Err.Number = 0 Then
output.WriteLine line & ",Error: " & Err.Description
On Error GoTo 0
Else
On Error GoTo 0
hostname = line

Set wmiResults = wmiService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

Dim item
For Each item In wmiResults
serialNumber = Trim(item.SerialNumber)
biosversion = Trim(item.SMBIOSBIOSVersion)
Next

Set wmiResults = wmiService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each item In wmiResults
make = Trim(item.Manufacturer)
model = Trim(item.Model)
computername = Trim(item.Name)
domain = Trim(item.Domain)
Next

Set wmiResults = wmiService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each item In wmiResults
operatingSystem = Trim(item.Name)
operatingSystem = Split(operatingSystem, "|")(0)
memory = Round(Trim(item.TotalVisibleMemorySize) / 1024, 2)
Next

Set wmiResults = wmiService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each item In wmiResults
cpu = Trim(item.Name)
Next

Set wmiResults = wmiService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter = 1", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each item In wmiResults
mac = Trim(item.MACAddress)
Next

Set wmiResults = wmiService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType=3", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each item In wmiResults
drives = drives & Trim(item.DeviceID) & " " & Round(Trim(item.Size) / (1024^2), 2) & ";"
Next

output.WriteLine hostname & "," & computername & "," & domain & "," & serialNumber & "," & make & "," & model & "," & biosversion & "," & operatingSystem & "," & cpu & "," & memory & "," & drives & "," & mac
End If
Else
output.WriteLine line & ",No Response"
End If
Wend

output.Close
input.Close

Set wmiService = Nothing
Set wmiresults = Nothing

Msgbox("Done Collecting Data")

さらに、私のネットワークには、このコードが停止する特定の IP があります。これを実行し続ける方法はありますか?

答え1

必要な範囲の大きさ/柔軟性によって異なります。

最も単純な形では

baseIP="10.10."

for a=0 to 255
  for b=0 to 255

IP=baseIP&a&"."&b

<\Your code here>

  next b
next a

もっと後で

サブネット検索に似たもの

main

sub main

Dim WshShell, oExec
Dim x

Set wshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objInputFile = objFSO.OpenTextFile("c:\scripts\computers.txt",1)

Do until objInputFile.AtEndofStream
userIP = objInputFile.ReadLine


numBits=Mid(userIP,instr(1,userIP,"/")+1,3)
numIP=CDbl(2^(32-mid(userIP,instr(1,userIP,"/")+1,3)))
ip=Mid(userIP,1,instr(1,userIP,"/")-1)

a=Split(ip,".")
'Darn vbscript has signed numbers so -2 billion to pos 2 billion
' and ip's go 0 to 4 billion
'lame work around
If a(0)>127 Then offset=128 Else offset=0
a(0)=a(0)-offset

ipnum=CDbl((a(0)*256^3)+(a(1)*256^2)+(a(2)*256)+a(3))
ipEnd=CDbl(ipnum+numIP)

For x=ipnum To ipEnd

grab=Hex(x)
grab2=Mid("00000000"&grab,Len(grab)+1,8)

a=CLng("&h"&Mid(grab2,1,2))+offset
b=CLng("&h"&Mid(grab2,3,2))
c=CLng("&h"&Mid(grab2,5,2))
d=CLng("&h"&Mid(grab2,7,2))

newip=a&"."&b&"."&c&"."&d
WScript.echo "newip:"&newip

inventory(newip)
Next 

Loop

end sub

開始IPアドレスと終了IPアドレス

begIP="10.10.3.1"
endIP="10.10.10.1"

a=Split(begIP,".")
b=Split(endIP,".")
'Darn vbscript has signed numbers so -2 billion to pos 2 billion
' and ip's go 0 to 4 billion
'lame work around
If a(0)>127 Then offset=128 Else offset=0
a(0)=a(0)-offset
b(0)=b(0)-offset
ipnum=CDbl((a(0)*256^3)+(a(1)*256^2)+(a(2)*256)+a(3))

ipEnd=CDbl((b(0)*256^3)+(b(1)*256^2)+(b(2)*256)+b(3))

For x=ipnum To ipEnd

grab=Hex(x)
grab2=Mid("00000000"&grab,Len(grab)+1,8)

a=CLng("&h"&Mid(grab2,1,2))+offset
b=CLng("&h"&Mid(grab2,3,2))
c=CLng("&h"&Mid(grab2,5,2))
d=CLng("&h"&Mid(grab2,7,2))

newip=a&"."&b&"."&c&"."&d
WScript.echo "newip:"&newip
inventory(newip)

Next 
end sub

関連情報