I was working on this this morning, but had to stop to take my windstar to the transmission shop...
Would it be best to filter out the non-pingables?
This can go in one of 2 directions:
1 a subnet monitor to show what is online
2 a uptime monitor to inform if something goes down.
You really wouldn't want to be constantly pinging EVERYTHING on a subnet, so ping everything on demand or ping a few things repeatedly...
You can see what I was looking to do. If you do not enter an IP, it takes your current IP and assumes Class C subnet. Otherwise input CIDR of the target network
Code:
Break On
$System = CreateObject("Kixtart.System")
;************* Form **************
$Form = $System.Form()
$Form.Height = 350
$Form.Left = 37
$Form.Text = "Subnet Pinger"
$Form.Top = 22
$Form.Width = 250
;**************************************
$PanelTop = $Form.Panel()
$PanelTop.BorderStyle = 1
$PanelTop.Dock = 1
$PanelTop.Height = 35
$nul = $Form.Controls.Add($PanelTop)
$PanelBottom = $Form.Panel()
$PanelBottom.BorderStyle = 1
$PanelBottom.Dock = 2
$PanelBottom.Height = 25
$nul = $Form.Controls.Add($PanelBottom)
$PanelCenter = $Form.Panel()
$PanelCenter.BorderStyle = 1
$PanelCenter.Dock = 5
$nul = $Form.Controls.Add($PanelCenter)
$TextBox3 = $Form.TextBox('',5,5,145,20)
$Button4 = $Form.Button('Load Subnet',160,5,75,20)
$button4.OnClick = "LoadSubnet"
$ListView5 = $PanelCenter.ListView()
$ListView5.Dock = 5
$ListView5.GridLines = "True"
$ListView5.AllowColumnReorder = "True"
$ListView5.FullRowSelect = "True"
$nul = $PanelCenter.Controls.Add($ListView5)
$nul = $ListView5.Columns.Add("IPAddress",100)
$nul = $ListView5.Columns.Add("Status",119)
$nul = $PanelTop.Controls.Add($TextBox3)
$nul = $PanelTop.Controls.Add($Button4)
$Form.Show
While $Form.Visible
$=Execute($Form.DoEvents())
Loop
Exit 1
Function LoadSubnet
if not instr($TextBox3.Text,'.')
$TextBox3.Text =join(split(@IPADDRESS0),'')
endif
$ListView5.Items.Clear
if not instr($TextBox3.Text,"/")
$TextBox3.Text = $TextBox3.Text +'/24'
endif
$arrIPs = EnumIPRange($TextBox3.Text)
for each $ip in $arrIPs
if Ping($ip)
$item = $ListView5.Items.Add($IP)
endif
next
EndFunction
Function Ping($PC)
DIM $PC
shell '%Comspec% /C ping -n 1 ' + $PC + ' | find /C "TTL=" > nul'
$Ping = NOT @ERROR
EndFunction
Function EnumIPRange($sIPaddress,optional $sNetMask)
Dim $aiStartRange,$aiMaskBits,$aiEndRange[4],$iHostCount,$i
Dim $cidr,$fac,$mask,$temp,$temp2,$a,$b
Dim $iOctet1,$iOctet2,$iOctet3,$iOctet4
Dim $tempArray[1],$arrOctect[4]
if instr($sIPaddress,'/')
$cidr=val(split($sIPaddress,'/')[1])
$sIPaddress=split($sIPaddress,'/')[0]
$sNetMask=''
for $a = 1 to $cidr
$mask=$mask+'1'
next
for $a = $cidr + 1 to 32
$mask=$mask+'0'
next
for $a = 0 to 3
$temp=substr($mask,$a*8+1,8)
$temp2=0
$fac=256
for $b=1 to 8
$fac = $fac / 2
$temp2 = $temp2 + val(substr($temp,$b,1)) * $fac
next
if not $a=3
$sNetMask=$sNetMask+$temp2+ '.'
else
$sNetMask=$sNetMask+$temp2
endif
next
endif
$iHostCount=1
$aiStartRange=Split($sIPaddress,".")
$aiMaskBits=Split($sNetMask,".")
Redim Preserve $aiStartRange[4]
Redim Preserve $aiMaskBits[4]
For $i = 0 To 3
$aiMaskBits[$i] =Val($aiMaskBits[$i]) & 255
$aiStartRange[$i] =Val($aiStartRange[$i]) & $aiMaskBits[$i]
$aiEndRange[$i] =$aiStartRange[$i]+(255-$aiMaskBits[$i])
$iHostCount =$iHostCount*($aiEndRange[$i]-$aiStartRange[$i]+1)
Next
redim $temparray[$iHostCount]
$i=0
For $iOctet1 = $aiStartRange[0] To $aiEndRange[0]
For $iOctet2 = $aiStartRange[1] To $aiEndRange[1]
For $iOctet3 = $aiStartRange[2] To $aiEndRange[2]
For $iOctet4 = $aiStartRange[3] To $aiEndRange[3]
$temparray[$i]=''+$iOctet1+'.'+$iOctet2+'.'+$iOctet3+'.'+$iOctet4
$i=$i+1
Next
Next
Next
Next
$EnumIPRange=$temparray
EndFunction