JeffQOOQAAA

arp -a output .txt

34 posts in this topic

Dears

If I want to excuete arp -a command line via autoit, and all information output .txt

Is possibly?

Need use StringRegExp function?

Share this post


Link to post
Share on other sites



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)

Share this post


Link to post
Share on other sites

?

#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)

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

@jguinch Sorry to bother.
I only want to get type is "dynamic" 
May I use this function?

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

@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)

 

1 person likes this

Share this post


Link to post
Share on other sites

#11 ·  Posted

@jguinch

I only want to get type is "dynamic"and ip"192.168..."  IP....

Share this post


Link to post
Share on other sites

#12 ·  Posted

@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 ?

 

1 person likes this

Share this post


Link to post
Share on other sites

#14 ·  Posted

Thanks all

I will try it

Share this post


Link to post
Share on other sites

#15 ·  Posted (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 by jguinch

Share this post


Link to post
Share on other sites

#16 ·  Posted

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

Share this post


Link to post
Share on other sites

#18 ·  Posted

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)

Share this post


Link to post
Share on other sites

#20 ·  Posted

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   

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now