hamohd70 Posted August 31, 2014 Share Posted August 31, 2014 I'm writing a small LAN scanner to fit my purpose but I find the classical ping command is too slow. As a work around, I'm planning to ask the user to limit the range of IPs to be scanned but I thinks it is always better if I can develop or fnd a faster way to do this. expandcollapse popup#include <Constants.au3> $vGateway = _IPConfig() _ScanLAN($vGateway) Func _IPConfig() Local $iPID, $sOutput = '' $iPID = Run(@ComSpec & ' /c ipconfig', @SystemDir, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD) While 1 $sOutput = StdoutRead($iPID) If @error Then ExitLoop if StringInStr($sOutput," Default Gateway . . . . . . . . . : ") Then $sOutput=StringMid($sOutput,StringInStr($sOutput," Default Gateway . . . . . . . . . : ") + StringLen(" Default Gateway . . . . . . . . . : "), 15) Return $sOutput ExitLoop EndIf WEnd EndFunc Func _ScanLAN($vGatewayIP) Local $iPID, $sOutput = '' local $array=StringSplit($vGatewayIP,".") $BaseIP = $array[1] & "." & $array[2] & "." & $array[3] & "." $iPID = Run('"' & @ComSpec & '"', '', @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD) for $i = 100 to 150 $command = "ping -a -n 1 " & $BaseIP & $i ConsoleWrite($command & @CRLF) StdinWrite($iPID,$command & @CRLF) While 1 $sOutput = StdoutRead($iPID) If @error Then ExitLoop if StringRight($sOutput,1) = ">" Then ExitLoop if StringInStr($sOutput,"Pinging ") Then If StringInStr($sOutput, "[") Then $StartLocation = StringInStr($sOutput,"Pinging ") + StringLen("Pinging ") $EndLocation = StringInStr($sOutput, "[") $sOutput=StringMid($sOutput,$StartLocation, $EndLocation - $StartLocation) ConsoleWrite ($sOutput & @CRLF) ExitLoop EndIf EndIf WEnd Next EndFunc here the code I wrote: Link to comment Share on other sites More sharing options...
Zer0Velocity Posted August 31, 2014 Share Posted August 31, 2014 Maybe you might want to look at this udf Link to comment Share on other sites More sharing options...
hamohd70 Posted August 31, 2014 Author Share Posted August 31, 2014 thanks alot. I will try it. Link to comment Share on other sites More sharing options...
jguinch Posted August 31, 2014 Share Posted August 31, 2014 hamohd70, you _IPConfig() function only works with an english OS. It might be interesting to not use an external program to get the gateway, no ? And careful, sometimes there are several gateways (when there is more than one NIC - with laptop for example) Here is a small code, using registry to retrieve all gateways : #Include <Array.au3> Local $sKey = "HKLM\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces" Local $i = 0, $n = 0 Local $aGateways[1] Local $sGateway, $sInterfaces, $sDefaultGateway, $sDhcpDefaultGateway While 1 $sGateway = "" $sInterfaces = RegEnumKey($sKey , $i + 1) If @error Then ExitLoop $sDefaultGateway = RegRead($sKey & "\" & $sInterfaces, "DefaultGateway") $sDhcpDefaultGateway = RegRead($sKey & "\" & $sInterfaces, "DhcpDefaultGateway") If $sDefaultGateway <> "" Then $sGateway = $sDefaultGateway ElseIf $sDhcpDefaultGateway <> "" Then $sGateway = $sDhcpDefaultGateway EndIf If $sGateway <> "" Then $n += 1 Redim $aGateways[$n] $aGateways[$n - 1] = $sGateway EndIf $i += 1 WEnd _ArrayDisplay($aGateways) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
hamohd70 Posted September 2, 2014 Author Share Posted September 2, 2014 thank u all for the help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now