jguinch Posted February 20, 2017 Share Posted February 20, 2017 StringRegExp($sData, "(?:\d+\.){3}\d+", 3) 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 20, 2017 Share Posted February 20, 2017 What about a function: Credit to jguinch for RegExp #Include <Array.au3> #Include <AutoItConstants.au3> $aARP_192168 = ARP_OUTPUT('192.168', 'dynamic') _ArrayDisplay($aARP_192168) Func ARP_OUTPUT($ipRange, $ipType) 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[0][3] For $i = 0 To UBound($aArpTable) - 1 Step 3 If StringStripWS($aArpTable[$i + 2], 7) <> $ipType Then ContinueLoop If StringLeft(StringStripWS($aArpTable[$i], 7), StringLen($ipRange)) <> $ipRange Then ContinueLoop _ArrayAdd($aArpTable2D, $aArpTable[$i] & '|' & $aArpTable[$i + 1] & '|' & $aArpTable[$i + 2]) Next Return $aArpTable2D EndFunc Link to comment Share on other sites More sharing options...
jguinch Posted February 20, 2017 Share Posted February 20, 2017 Here is the best method : 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 Thanks for your help! Thanks a lot. StrginRegExp function is very difficult for me....... Link to comment Share on other sites More sharing options...
antonioj84 Posted May 6, 2017 Share Posted May 6, 2017 (edited) I want to retrieve the mac address at "Physical address collumn" it start with 90 see below Edited May 6, 2017 by antonioj84 correction Link to comment Share on other sites More sharing options...
antonioj84 Posted May 6, 2017 Share Posted May 6, 2017 I did some further digging I realised the MAC address always start by 90 for that device,, can someone provide a snippet "Physical address collumn" Link to comment Share on other sites More sharing options...
Subz Posted May 6, 2017 Share Posted May 6, 2017 Try the following, you can use partial string (left to right) of what ever you like to search for e.g IP Address "192.168", Mac Address "90-"or Type "Static", you can leave fields blank to return the entire arp list. #Include <Array.au3> #Include <AutoItConstants.au3> $aARP_192168 = ARP_OUTPUT('', '90-', '') _ArrayDisplay($aARP_192168) Func ARP_OUTPUT($vIPAddress = '', $vMacAddress = '', $vType = '') 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[0][3] For $i = 0 To UBound($aArpTable) - 1 Step 3 If $vIPAddress <> '' And StringLeft(StringStripWS($aArpTable[$i], 7), StringLen($vIPAddress)) <> $vIPAddress Then ContinueLoop If $vMacAddress <> '' And StringLeft(StringStripWS($aArpTable[$i + 1], 7), StringLen($vMacAddress)) <> $vMacAddress Then ContinueLoop If $vType <> '' And StringStripWS($aArpTable[$i + 2], 7) <> $vType Then ContinueLoop _ArrayAdd($aArpTable2D, $aArpTable[$i] & '|' & $aArpTable[$i + 1] & '|' & $aArpTable[$i + 2]) Next Return $aArpTable2D EndFunc antonioj84 1 Link to comment Share on other sites More sharing options...
antonioj84 Posted May 6, 2017 Share Posted May 6, 2017 Thanks again Subz Link to comment Share on other sites More sharing options...
antonioj84 Posted May 6, 2017 Share Posted May 6, 2017 Thanks for the snippet it works and exactly what I need, however I want to learn as well can you explain in lemon term your regex what it does Local $aArpTable = StringRegExp($sArp, "((?:\d+\.){3}\d+)\h+((?:[[:xdigit:]]{2}-){5}[[:xdigit:]]{2})\h+(\V+)", 3) Link to comment Share on other sites More sharing options...
Subz Posted May 7, 2017 Share Posted May 7, 2017 RegEx confuses me as well, for me the easiest method for breaking down a regular expression is to use https://regex101.com, there are some tools you can download as well, but prefer this method personally: Insert the regular expression pattern in the "Regular Expression" pane: ((?:\d+\.){3}\d+)\h+((?:[[:xdigit:]]{2}-){5}[[:xdigit:]]{2})\h+(\V+) Then add a line from cmd arp-a to the "Test String" panel: 192.168.150.255 ff-ff-ff-ff-ff-ff static On the right hand side panels it explains everything rather nicely and is color coded. Hope that helps. Link to comment Share on other sites More sharing options...
jguinch Posted May 9, 2017 Share Posted May 9, 2017 (edited) \d : One digit\d+ : One or more digits\h : One horizontal whitespace\h+ : One or more horizontal whitespaces\. : . (dot)\V+ : One or more characters mathing a non-vertical character[:xdigit:] : One hexadecimal digit[:xdigit:]{2} : Two hexadecimal digits() : Capturing group (what you want to retrieve in the returned array)(?:) : Non-capturing group (useful to use with quantifier) ((?:\d+\.){3}\d+)\h+((?:[[:xdigit:]]{2}-){5}[[:xdigit:]]{2})\h+(\V+) : ((?:\d+\.){3}\d+) : (1st group) (One or more digits ,and a dot) 3 times, and one or more digits \h+ : One or more horizontal whitespaces((?:[[:xdigit:]]{2}-){5}[[:xdigit:]]{2}) : (2nd group) (Two hexadecimal digits and a dash) 5 times, and two hexadecimal digits \h+ : One or more horizontal whitespaces(\V+) : (3rd group) : One or more characters mathing a non-vertical character (used to match all characters until the end of the line) https://regex101.com/r/aPdHcf/1 Edited May 9, 2017 by jguinch antonioj84 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
antonioj84 Posted May 30, 2017 Share Posted May 30, 2017 I have a question to the expert. I can use arp -s $ipaddress $Macaddress to write the the ip address to the device interface, however is there a way of to programmatically add the gateway and the subnet also. Or by pinging the device it will add the correct gateway and subnet. Thanks ahead Link to comment Share on other sites More sharing options...
antonioj84 Posted May 31, 2017 Share Posted May 31, 2017 (edited) wrong Edited May 31, 2017 by antonioj84 error Link to comment Share on other sites More sharing options...
antonioj84 Posted May 31, 2017 Share Posted May 31, 2017 #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) can you explain in a lemon term that line below Local $sCmd = 'for /f "tokens=1,2 delims= " %a in (''arp -a ^| findstr "dyn stat"'') do @echo %a;%b' 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