JeffQOOQAAA Posted February 16, 2017 Share Posted February 16, 2017 Dears If I want to excuete arp -a command line via autoit, and all information output .txt Is possibly? Need use StringRegExp function? Link to comment Share on other sites More sharing options...
jguinch Posted February 16, 2017 Share Posted February 16, 2017 Yes it's possible. What did you try ? StringRegExp can be a good use, but you have to get the result of the ARP command before. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
JeffQOOQAAA Posted February 16, 2017 Author Share Posted February 16, 2017 I want to use StringRegExp and only catch 192.168.xxxxxx information. But I have no idea how to do this...... While 1 _netView() Sleep(1000) WEnd Func _netView() $PID = Run("cmd /c arp -a","",@SW_HIDE,$STDOUT_CHILD+$STDERR_CHILD) Dim $Read = '', $ErrorRead = '' While ProcessExists($PID) $Read &= StdoutRead($PID) $ErrorRead &= StderrRead($PID) WEnd $Read &= StdoutRead($PID) $ErrorRead &= StderrRead($PID) $ComputerName = StringRegExp($Read,"192.168",3) Link to comment Share on other sites More sharing options...
jguinch Posted February 16, 2017 Share Posted February 16, 2017 ? #Include <Array.au3> #Include <AutoItConstants.au3> Local $iPid = Run("cmd /c arp -a","",@SW_HIDE,$STDOUT_CHILD) ProcessWaitClose($iPid) Local $sArp = StdoutRead($iPid) Local $aArpTable = StringRegExp($sArp, "(192\.168\.\d+\.\d+)\h+((?:[[:xdigit:]]{2}-){5}[[:xdigit:]]{2})", 3) Local $aArpTable2D[ UBound($aArpTable) / 2][2] For $i = 0 To UBound($aArpTable) - 1 Step 2 $aArpTable2D[$i / 2][0] = $aArpTable[$i] $aArpTable2D[$i / 2][1] = $aArpTable[$i + 1] Next _ArrayDisplay($aArpTable2D) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
JeffQOOQAAA Posted February 17, 2017 Author Share Posted February 17, 2017 Thanks a lot My regular expression is very weakness..... If I want to get Type is dynamic and IP address 192.168.X.X Is possibly? Link to comment Share on other sites More sharing options...
jguinch Posted February 17, 2017 Share Posted February 17, 2017 Use this regex instead : Local $aArpTable = StringRegExp($sArp, "(192\.168\.\d+\.\d+)\h+(?:[[:xdigit:]]{2}-){5}[[:xdigit:]]{2}\h+(\V+)", 3) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
JohnOne Posted February 17, 2017 Share Posted February 17, 2017 'cmd /c arp -a | findstr "192.168"' might help AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JeffQOOQAAA Posted February 18, 2017 Author Share Posted February 18, 2017 @jguinch Sorry to bother. I only want to get type is "dynamic" May I use this function? Link to comment Share on other sites More sharing options...
jguinch Posted February 18, 2017 Share Posted February 18, 2017 My regex in #6 returns each IP address with the type. You want to get only the type ? Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Subz Posted February 18, 2017 Share Posted February 18, 2017 @jguinch How would you get the full arp table like below with RegEx? Local $iPid = Run("cmd /c arp -a","",@SW_HIDE,$STDOUT_CHILD) ProcessWaitClose($iPid) Local $sArp = StdoutRead($iPid) Local $aArpTable = StringSplit($sArp, @LF) Local $aArpTable1D ;~ String Split Local $aArpTable2D[1][3] For $i = $aArpTable[0] To 1 Step - 1 If StringStripWS($aArpTable[$i], 8) = '' Then ContinueLoop $aArpTable1D = StringSplit(StringStripWS($aArpTable[$i], 7), ' ', 2) _ArrayTranspose($aArpTable1D) If UBound($aArpTable1D, 2) = 3 Then _ArrayConcatenate($aArpTable2D, $aArpTable1D) Next _ArraySort($aArpTable2D, 0, 1) $aArpTable2D[0][0] = UBound($aArpTable2D) - 1 _ArrayDisplay($aArpTable2D) antonioj84 1 Link to comment Share on other sites More sharing options...
JeffQOOQAAA Posted February 18, 2017 Author Share Posted February 18, 2017 @jguinch I only want to get type is "dynamic"and ip"192.168..." IP.... Link to comment Share on other sites More sharing options...
jguinch Posted February 18, 2017 Share Posted February 18, 2017 @Subz : pretty much the same thing than #4 : #Include <Array.au3> #Include <AutoItConstants.au3> Local $iPid = Run("cmd /c arp -a","",@SW_HIDE,$STDOUT_CHILD) ProcessWaitClose($iPid) Local $sArp = StdoutRead($iPid) Local $aArpTable = StringRegExp($sArp, "((?:\d+\.){3}\d+)\h+((?:[[:xdigit:]]{2}-){5}[[:xdigit:]]{2})\h+(\V+)", 3) Local $aArpTable2D[ UBound($aArpTable) / 3 + 1][3] = [[UBound($aArpTable) / 3]] For $i = 0 To UBound($aArpTable) - 1 Step 3 $aArpTable2D[$i / 3 + 1][0] = $aArpTable[$i] $aArpTable2D[$i / 3 + 1][1] = $aArpTable[$i + 1] $aArpTable2D[$i / 3 + 1][2] = $aArpTable[$i + 2] Next _ArrayDisplay($aArpTable2D) @JeffQOOQAAA : just take the code in #4 and replace the regex ligne with #6. You didn't try ? Subz 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
JohnOne Posted February 18, 2017 Share Posted February 18, 2017 'cmd /c arp -a | findstr "192.168" | findstr "static"' jguinch 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JeffQOOQAAA Posted February 20, 2017 Author Share Posted February 20, 2017 Thanks all I will try it Link to comment Share on other sites More sharing options...
jguinch Posted February 20, 2017 Share Posted February 20, 2017 (edited) For the fun, another way (using the option 4 with StringRegExp): #Include <Array.au3> #Include <AutoItConstants.au3> Local $sCmd = 'for /f "tokens=1,2 delims= " %a in (''arp -a ^| findstr "dyn stat"'') do @echo %a;%b' Local $iPid = Run(@ComSpec & " /c " & $sCmd,@SystemDir,@SW_HIDE,$STDOUT_CHILD) ProcessWaitClose($iPid) Local $sArp = StdoutRead($iPid) Local $aData = StringRegExp($sArp, "([^;]+);(\V+)", 4) Local $aResult[UBound($aData)][2] For $i = 0 To UBound($aData) - 1 $aResult[$i][0] = ($aData[$i])[1] $aResult[$i][1] = ($aData[$i])[2] Next _ArrayDisplay($aResult) Edited February 20, 2017 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
JeffQOOQAAA Posted February 20, 2017 Author Share Posted February 20, 2017 Dears. I get some information in .txt, how do I only add IP to array ? 192.168.1.12 f0-76-1c-6a-4c-88 dynamic 192.168.1.14 f0-76-1c-b7-1b-81 dynamic NetViewReport.txt Link to comment Share on other sites More sharing options...
jguinch Posted February 20, 2017 Share Posted February 20, 2017 Which array ? Which code ? Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
JeffQOOQAAA Posted February 20, 2017 Author Share Posted February 20, 2017 Sorry, I forgot Local $iPid = Run("cmd /c arp -a | findstr " & $ip & "| findstr " & $dynamic,"",@SW_HIDE,$STDOUT_CHILD) ProcessWaitClose($iPid) Local $sArp = StdoutRead($iPid) FileWrite(@DesktopDir & "\NetViewReport.txt",$sArp & @CRLF) For $i = 0 To UBound($sArp) - 1 _ArrayAdd($aArray_Net, $sArp[$i]) Next _ArrayDisplay($aArray_Net) Link to comment Share on other sites More sharing options...
jguinch Posted February 20, 2017 Share Posted February 20, 2017 (edited) Why are you writting the data in a file ? Previous codes didn't work ? In your code, $sArp is not an array, so it cannot work. Edited February 20, 2017 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
JeffQOOQAAA Posted February 20, 2017 Author Share Posted February 20, 2017 Sorry, Due to only want to IP address in array, not other information I want to know how to use stringRegExp function get to array ? 192.168.1.12 f0-76-1c-6a-4c-88 dynamic 192.168.1.14 f0-76-1c-b7-1b-81 dynamic 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