Skip to content

Instantly share code, notes, and snippets.

@lowweihong
Last active July 13, 2019 03:48
Show Gist options
  • Save lowweihong/f050abeda7d31579b10f1acba1a30213 to your computer and use it in GitHub Desktop.
Save lowweihong/f050abeda7d31579b10f1acba1a30213 to your computer and use it in GitHub Desktop.
Web protocol example
from websocket import create_connection
import json
import pprint
# Initialize the headers needed for the websocket connection
headers = json.dumps({
'Date': 'Sun, 27 Aug 2017 09:42:15 GMT',
'Connection': 'upgrade',
'Host': 'www.kolumbus.no',
'Origin': 'https://www.kolumbus.no',
'Cookie': '.ASPXANONYMOUS=n3-SNfanLhJJsZsOZrYNFUMLRKd3aml7MYJ14xVgBBRZ0KLdZzWd5ncc3gEjCXtJ01XbHxnrt2lp0on3dJtFio6kl03eMDhJsRjZJ4MvgKr7atnbvuF6A-9UB9vJV-Uryhwj1RmxRhe9eIMrid3G5Q2; _gcl_au=1.1.1328331494.1562895478; _ga=GA1.2.17927177.1562895478; ASP.NET_SessionId=4iw2ui4kvnbkufrmxvk1isxd; _gid=GA1.2.1450924434.1562987695',
'Upgrade': 'websocket',
'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits',
'Sec-WebSocket-Key': 'a68fttH5Qvlftz/NQuCRZg==',
'Sec-WebSocket-Version': '13',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Pragma': 'no-cache',
'Upgrade': 'websocket'
})
# Then create a connection to the tunnel
ws = create_connection(
'wss://www.kolumbus.no/signalr/connect?transport=webSockets&clientProtocol=1.5&version=3.1.1178.0&connectionToken=ELuhRv%2Be1wZats9iiz2%2Buy%2FYygRzGXEEVVvVNZdp5eHyhJglqMZ7cc%2BMSHSvExwbE6%2F5ARijfP42DAdYVIbOGrOP1tORtol3wP%2F57urbvJdMVYzLRa2agAoSP0hlm8As&connectionData=%5B%7B%22name%22%3A%22publicmaphub%22%7D%5D&tid=6',headers=headers)
# Then send a message through the tunnel
ws.send('{"H":"publicmaphub","M":"getData","A":[],"I":1}')
# Here you will view the message return from the tunnel
while True:
pprint.pprint(json.loads(ws.recv()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment