我需要使用 Python 套接字发送 SIP 消息,我已经让客户端向服务器发送一些内容,但我无法让客户端向服务器发送 SIP 消息 INVITE
#!/usr/bin/python
import socket
R_IP = '192.168.2.1'
R_PORT = 5060
message = 'INVITE sip:[email protected] /cdn-cgi/l/email-protection SIP/2.0 To: <sip:[email protected] /cdn-cgi/l/email-protection>\x0d\x0aFrom: sip:[email protected] /cdn-cgi/l/email-protection;tag=R400_BAD_REQUEST;taag=4488.1908442942.0\x0d\x0aP-Served-User: sip:[email protected] /cdn-cgi/l/email-protection\x0d\x0aCall-ID: [email protected] /cdn-cgi/l/email-protection\x0d\x0aCSeq: 1 INVITE\x0d\x0aContact: sip:[email protected] /cdn-cgi/l/email-protection\x0d\x0aMax-Forwards: 70\x0d\x0aVia: SIP/2.0/TCP 10.44.40.47;branch=z9hG4bK1908442942.4488.0\x0d\x0aContent-Length: 10\x0d\x0a\x0d\x0aRandomText'
def sendPacket():
proto = socket.getprotobyname('tcp')
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)#, proto)
try:
s.connect((R_IP , R_PORT))
s.sendall(message)
except socket.error:
pass
finally:
s.close()
sendPacket()
你有什么想法吗?
根据RFC 3261 https://www.rfc-editor.org/rfc/rfc3261:
- 每个标头必须以换行符开头,并且标头名称之前不能有空格。
- 最小 SIP 请求必须包含
To
, From
, CSeq
, Call-ID
, Max-Forwards
and Via
标头。
这意味着您之前正确添加了换行符To
标题,但您的答案也错误地包含Froma
标题而不是From
。另外,标头P-Served-User
一般是没有必要的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)