Sign in to follow this  
Followers 0
tbaror

Tshark query parsing to table(array)

3 posts in this topic

Hello All,

I need to parse into table array a plot from Tshark as follows below, the issue i got with that specific that table size could change and different terms could be in it.

i know how to use regexp but i have difficulty realize the right pattern or the idea to parse this kind of table.

Please advice

Thanks

===================================================================
SMB RTT Statistics:
Filter:
Commands                   Calls   Min RTT   Max RTT   Avg RTT
Trans                          6   0.00025   0.00142   0.00064
Tree Disconnect                4   0.00012   0.00036   0.00023
Negotiate Protocol             2   0.00042   0.00042   0.00042
Session Setup AndX             3   0.00030   0.00131   0.00074
Logoff AndX                    2   0.00017   0.00055   0.00036
Tree Connect AndX              4   0.00013   0.00064   0.00031

Transaction2 Commands      Calls   Min RTT   Max RTT   Avg RTT
FIND_FIRST2                  194   0.00019   0.00033   0.00024
QUERY_PATH_INFO              428   0.00016   0.00198   0.00026
GET_DFS_REFERRAL               3   0.00019   0.00028   0.00024

NT Transaction Commands    Calls   Min RTT   Max RTT   Avg RTT
===================================================================

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here's my attempt. You may find a better way to filter out the data you don't need.

#include <Array.au3>
$sText = "===================================================================" & @CRLF
$sText &= "SMB RTT Statistics:" & @CRLF
$sText &= "Filter:" & @CRLF
$sText &= "Commands                   Calls   Min RTT   Max RTT   Avg RTT" & @CRLF
$sText &= "Trans                          6   0.00025   0.00142   0.00064" & @CRLF
$sText &= "Tree Disconnect                4   0.00012   0.00036   0.00023" & @CRLF
$sText &= "Negotiate Protocol             2   0.00042   0.00042   0.00042" & @CRLF
$sText &= "Session Setup AndX             3   0.00030   0.00131   0.00074" & @CRLF
$sText &= "Logoff AndX                    2   0.00017   0.00055   0.00036" & @CRLF
$sText &= "Tree Connect AndX              4   0.00013   0.00064   0.00031" & @CRLF
$sText &= @CRLF
$sText &= "Transaction2 Commands      Calls   Min RTT   Max RTT   Avg RTT" & @CRLF
$sText &= "FIND_FIRST2                  194   0.00019   0.00033   0.00024" & @CRLF
$sText &= "QUERY_PATH_INFO              428   0.00016   0.00198   0.00026" & @CRLF
$sText &= "GET_DFS_REFERRAL               3   0.00019   0.00028   0.00024" & @CRLF
$sText &= @CRLF
$sText &= "NT Transaction Commands    Calls   Min RTT   Max RTT   Avg RTT" & @CRLF
$sText &= "==================================================================="
$aTemp = StringSplit($sText, @CRLF)
$i = 1
While $i <= UBound($aTemp) - 1
    If StringInStr($aTemp[$i], "=") Or StringInStr($aTemp[$i], ":") Or StringInStr($aTemp[$i], "Transaction") Or $aTemp[$i] = "" Then
        _ArrayDelete($aTemp, $i)
        $aTemp[0] -= 1
        $i -= 1
    EndIf
    $i += 1
WEnd
For $iRow = 1 To UBound($aTemp) - 1
    $aTemp[$iRow] = StringRegExpReplace($aTemp[$iRow], "\s{2,}", @TAB)
Next
$iRows = $aTemp[0]
$aSplit = StringSplit($aTemp[1], @TAB)
$iCols = $aSplit[0]
Dim $aArray[$iRows][$iCols]
For $iRow = 1 To UBound($aTemp) - 1
    $aSplit = StringSplit($aTemp[$iRow], @TAB)
    For $iCol = 1 To UBound($aSplit) - 1
        $aArray[$iRow - 1][$iCol - 1] = $aSplit[$iCol]
    Next
Next
_ArrayDisplay($aArray)

Hello All,

I need to parse into table array a plot from Tshark as follows below, the issue i got with that specific that table size could change and different terms could be in it.

i know how to use regexp but i have difficulty realize the right pattern or the idea to parse this kind of table.

Please advice

Thanks

===================================================================
SMB RTT Statistics:
Filter:
Commands                   Calls   Min RTT   Max RTT   Avg RTT
Trans                          6   0.00025   0.00142   0.00064
Tree Disconnect                4   0.00012   0.00036   0.00023
Negotiate Protocol             2   0.00042   0.00042   0.00042
Session Setup AndX             3   0.00030   0.00131   0.00074
Logoff AndX                    2   0.00017   0.00055   0.00036
Tree Connect AndX              4   0.00013   0.00064   0.00031

Transaction2 Commands      Calls   Min RTT   Max RTT   Avg RTT
FIND_FIRST2                  194   0.00019   0.00033   0.00024
QUERY_PATH_INFO              428   0.00016   0.00198   0.00026
GET_DFS_REFERRAL               3   0.00019   0.00028   0.00024

NT Transaction Commands    Calls   Min RTT   Max RTT   Avg RTT
===================================================================

Edited by GMK

Share this post


Link to post
Share on other sites

Thanks ;) like a glove

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
Sign in to follow this  
Followers 0