Created
November 25, 2016 23:35
-
-
Save blha303/724bcc828da9a29947c39e168a540b7a to your computer and use it in GitHub Desktop.
Jackbox room code sniffer
This file contains hidden or 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
# a function to listen for the current jackbox room id being received | |
# requirements: pyshark python module, tshark library or wireshark | |
# sometimes the code gets cut off between packets. need to restart the current game if no code is found; this happens 10% of the time | |
def get_jackbox_room_code(packet_count=None): | |
""" blocks until room code is found or packet_count is reached | |
>>> get_jackbox_room_code() | |
'CTLE' """ | |
def get_outgoing_ip(): | |
import socket | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
s.connect(("8.8.8.8", 80)) | |
return s.getsockname()[0] | |
roomcode = "" | |
c = pyshark.LiveCapture(display_filter="websocket") | |
for packet in c.sniff_continuously(packet_count): | |
if packet.ip.addr[0] != get_outgoing_ip(): | |
try: | |
d = packet.websocket.payload_unknown.replace(":", "").decode('hex') | |
if '"roomId":"' in d: | |
roomcode = d.split('"roomId":"')[1].split('"')[0] | |
elif '","blob":{"state":"Lobby_WaitingForMore"}}' in d: | |
roomcode = d.split('","blob":{"state":"Lobby_WaitingForMore"}}')[0].split('"')[1] | |
except (AttributeError, IndexError): | |
pass | |
try: | |
d = packet.data.tcp_reassembled_data.replace(":", "").decode('hex') | |
if '"roomId":"' in d: | |
roomcode = d.split('"roomId":"')[1].split('"')[0] | |
elif '","blob":{"state":"Lobby_WaitingForMore"}}' in d: | |
roomcode = d.split('","blob":{"state":"Lobby_WaitingForMore"}}')[0].split('"')[1] | |
except (AttributeError, IndexError): | |
pass | |
if roomcode and len(roomcode) == 4: | |
break | |
return roomcode |
can someone tell me how to use this code
There's no guarantee it still works, this was written a long time ago.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I use this code?