Created
October 15, 2014 04:56
-
-
Save spicyramen/aa73c7376381c66c1054 to your computer and use it in GitHub Desktop.
Send SIP Register message via Secure Web Sockets
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
__author__ = 'gogasca' | |
#!/usr/bin/python | |
import websocket | |
import thread | |
import time | |
import ssl | |
register = "REGISTER sip:open-ims.test SIP/2.0\r\n" +\ | |
"Test-Header: 0\r\n" + \ | |
"v: SIP/2.0/UDP [::]:1988;test=1234;comp=sigcomp;rport=254;ttl=457;received=192.0.2.101;branch=z9hG4bK1245420841406\r\n" +\ | |
"f: \"Mamadou\" <sip:[email protected]>;tag=29358\r\n" +\ | |
"t: <sip:[email protected]>;tag= 12345\r\n" +\ | |
"i: M-fa53180346f7f55ceb8d8670f9223dbb\r\n" +\ | |
"CSeq: 201 REGISTER\r\n" +\ | |
"Max-Forwards: 70\r\n" +\ | |
"Allow: INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK\r\n" +\ | |
"Allow: REFER, UPDATE\r\n" +\ | |
"u: talk, hold, conference, LocalModeStatus\r\n" +\ | |
"m: <sip:[email protected]:5060;rtcweb-breaker=yes>;impi=78@sip2sip"+ "\r\n" +\ | |
"m: <sip:mamadou@[::]:1988;comp=sigcomp;transport=udp>;expires=600000;+deviceID=\"3ca50bcb-7a67-44f1-afd0-994a55f930f4\";mobility=\"fixed\";+g.3gpp.cs-voice;+g.3gpp.app%5fref=\"urn%3Aurnxxx%3A3gpp-application.ims.iari.gsmais\";+g.oma.sip-im.large-message;+g.oma.sip-im\r\n" +\ | |
"User-Agent: IM-client/OMA1.0 doubango/v0.0.0\r\n" +\ | |
"Require: pref, path\r\n" +\ | |
"Service-Route: <sip:[email protected]:6060;lr>,<sip:[email protected]:6060;lr>\r\n" +\ | |
"Path: <sip:[email protected]:4060;lr>\r\n" +\ | |
"Require: 100rel\r\n" +\ | |
"P-Preferred-Identity: <sip:[email protected]>\r\n" +\ | |
"k: path\r\n" +\ | |
"k: gruu, outbound, timer\r\n" +\ | |
"P-Access-Network-Info: 3GPP-UTRAN-TDD;utran-cell-id-3gpp=00000000\r\n" +\ | |
"Privacy: none;user;id\r\n" +\ | |
"Supported: gruu, outbound, path, timer\r\n" +\ | |
"Expires12: 1983\r\n" +\ | |
"l: 180\r\n" +\ | |
"\r\n" | |
InitRegister = "REGISTER sip:ramenlabs.io SIP/2.0\r\n" +\ | |
"Via: SIP/2.0/WSS df7jal23ls0d.invalid;branch=z9hG4bKe4gxQOl912qKBnwlzpo5ocWdnpGGvRwQ\r\n" + \ | |
"From: \"Gonzalo Gasca Meza\"<sip:[email protected]>;tag=APNcg8x8meV9cQElA4zr\r\n" +\ | |
"To: \"Gonzalo Gasca Meza\"<sip:[email protected]>\r\n" +\ | |
"Contact: \"Gonzalo Gasca Meza\"<sips:[email protected];rtcweb-breaker=no;transport=wss>;expires=200;click2call=no;cic=000\r\n" +\ | |
"Call-ID: ed038f1c-558a-0a2c-25c1-9bb7dfcea331\r\n" +\ | |
"CSeq: 38481 REGISTER\r\n" +\ | |
"Content-Length: 0\r\n" +\ | |
"Max-Forwards: 70\r\n" +\ | |
"User-Agent: Llamato client\r\n" +\ | |
"Organization: Ramen Labs\r\n" +\ | |
"Supported: path\r\n" + \ | |
"\r\n" | |
def on_message(ws, message): | |
print message | |
def on_error(ws, error): | |
print error | |
def on_close(ws): | |
print "### closed ###" | |
def on_open(ws): | |
def run(*args): | |
for i in range(10000): | |
time.sleep(1) | |
ws.send(InitRegister) | |
time.sleep(1) | |
ws.close() | |
print "thread terminating..." | |
thread.start_new_thread(run, ()) | |
if __name__ == "__main__": | |
custom_protocol = "sip" | |
protocol_str = "Sec-WebSocket-Protocol: " + custom_protocol | |
websocket.enableTrace(True) | |
wss = websocket.WebSocketApp("wss://ramenlabs.io:5063", | |
on_message = on_message, | |
on_error = on_error, | |
on_close = on_close, | |
header = [protocol_str]) | |
wss.on_open = on_open | |
wss.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For SIP Authorization support need to add SIP state machine