根据TCP协议,使用python在两进程之间建立通信,来模拟一个即时通信,类似于QQ
环境:kali 一个server.py和client.py
sever.py
# -*- coding: utf-8 -*
#Server.py
import socket
host = socket.gethostname()
port = 12345
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(1)
sock, addr = s.accept()
print "Linked"
info = sock.recv(1024)
while info != "exit":
print "From Others : "+info
send_mes = raw_input("")
sock.send(send_mes)
if send_mes == "exit":
break
info = sock.recv(1024)
sock.close()
s.close()
client.py
# -*- coding: utf-8 -*
#Client.py
import socket
s = socket.socket()
host = socket.gethostname()
port = 12345
s.connect((host, port))
print "Linked"
info = ""
while info != "exit":
print "From Others: "+info
send_mes = raw_input("")
s.send(send_mes)
if send_mes == "exit":
break
info = s.recv(1024)
s.close()
二个脚本需要同时运行,结果如下图
在kali上抓包简要分析一下
可以看出来我们刚刚之间传输的数据,从wireshark可以分析得到是使用TCP协议,发送一个包后会返回一个ACK包进行确认,然后再传输第二个包,以此类推