Skip to content

Instantly share code, notes, and snippets.

@blha303
Created November 25, 2016 23:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blha303/724bcc828da9a29947c39e168a540b7a to your computer and use it in GitHub Desktop.
Save blha303/724bcc828da9a29947c39e168a540b7a to your computer and use it in GitHub Desktop.
Jackbox room code sniffer
# 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
@Mathhog
Copy link

Mathhog commented Feb 13, 2018

How do I use this code?

@jackbox7
Copy link

can someone tell me how to use this code

@alyssadev
Copy link

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