Jump to content

arp -a output .txt


Recommended Posts

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

?

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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...