Last active
May 13, 2022 15:34
-
-
Save iAnatoly/f80088186410dd6a59c04a70aebb8ccf to your computer and use it in GitHub Desktop.
SIP ping
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
#!/usr/bin/env python3 | |
import socket | |
import time | |
userid = "trivial_sip_pinger" | |
domain = "<sip server to test>" | |
port = 5060 | |
timeout_ms = 1000 | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
sock.settimeout(timeout_ms / 1000.0) | |
sock.connect((domain,port)) | |
ip,localport = sock.getsockname() | |
packet = """OPTIONS sip:{domain} SIP/2.0 | |
Via: SIP/2.0/UDP {ip}:{localport} | |
To: "{userid}"<sip:{userid}@{domain}> | |
From: "{userid}"<sip:{userid}@{domain}> | |
Call-ID: nevermind | |
CSeq: 1 OPTIONS | |
Max-forwards: 10 | |
Content-Length: 0 | |
""".format(domain=domain, ip=ip, userid=userid, localport=localport) | |
# print(packet) | |
start = time.time() | |
sock.send(packet.encode('ascii')) | |
data, addr = sock.recvfrom(65535) | |
end = time.time() | |
diff = float("%.2f" % ((end - start) * 1000.0)) | |
response = data.decode('ascii') | |
print("Timing: {} ms\n\nResponse: {}".format(diff,response)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also: