-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* save send and receive packets in json * fix: undo some extra changes * cleanup and encode hex strings to base64 * a new way to detect middlebox, and detect PEP and NAT * fix 2/n * add paris argument * fix and cleanup 3/n * fix 4/n * set paris id * cleanup 4/n
- Loading branch information
Showing
5 changed files
with
333 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from base64 import b64encode | ||
|
||
|
||
# this function source: https://stackoverflow.com/a/64410921 | ||
def packet2json(packet_obj): | ||
packet_dict = {} | ||
layer = '' | ||
for line in packet_obj.show2(dump=True).split('\n'): | ||
if '###' in line: | ||
layer = line.strip('#[] ') | ||
packet_dict[layer] = {} | ||
elif '=' in line: | ||
key, val = line.split('=', 1) | ||
if layer == 'Raw' and key.strip() == 'load': | ||
packet_dict[layer][key.strip()] = b64encode( | ||
packet_obj['Raw'].load).decode() | ||
else: | ||
packet_dict[layer][key.strip()] = val.strip() | ||
return packet_dict | ||
|
||
|
||
def packetlist2json(answered, unanswered): | ||
packetlist = {'sent': [], 'received': []} | ||
if len(answered) == 0: | ||
if len(unanswered) != 0: | ||
packetlist["sent"] = packet2json(packet_obj=unanswered[0]) | ||
else: | ||
for sentp, receivedp in answered: | ||
if len(packetlist["sent"]) == 0: | ||
packetlist["sent"] = packet2json(packet_obj=sentp) | ||
packetlist["received"].append( | ||
packet2json(packet_obj=receivedp)) | ||
return packetlist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.