Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Network packet parsing routine

18 views
Skip to first unread message

Petr Laznovsky

unread,
Jun 4, 2017, 4:59:03 PM6/4/17
to
Utilizing PacketSender console utility, receiving 'UBNT discovery packet'
(https://github.com/nitefood/python-ubnt-discovery/blob/master/ubnt_discovery.py) and trying to
parse it for 'UBNT field types' (see link) content. Program output few lines (each line, one packet)
of spaces separated HEXA bytes. I am currently able to convert HEXA bytes into DEC or ASCII values
(see bottom), but not able get parsing logic :-/

Packet structure is following:

01 00 00 90 <-> 02 <-> 00 0A <-> DC 9F DB 40 2E 40 0A 0C 66 E3 .. .. .. .. .. .. .. ..

After four initial bytes, there is "constant" 02, than size of following content 00 0A (decadic 10),
and than content itself (MAC + IP in this case). This three items repeatedly makes whole packet´s
content. Rewriting whole routine three times, still cant get the right point. Do not expect full
code, only put me to right way please, because I am lost....

thanks, L.




:hex2dec
for /f %%a in ('set /a "0x%~1"') do set "%~2=%%~a"
GOTO:EOF

:hex2asc
REM == Replacing hexadecimal strings with its ASCII representation characters ==
call :hex_prep %~1
set "arg1=%str%"
set "arg1=%arg1:\x=0x%"
forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%arg1% > clip"
GOTO:EOF

:hex_prep
REM == Replace spaces by '\' and insert 'x' string before each token ===========
set "str="
:loop
if not "%str%"=="" (set "str=%str%\x%~1") else (set "str=\x%~1")
shift
if not "%~1"=="" goto loop
GOTO:EOF
0 new messages