简体   繁体   中英

Sniffing Socket Communication - Python

I'm using Socket communication to make two Raspberry Pi's communicate. And I'm using python. The program is very simple, because I'm trying to test the socket communication and how can two Pi's communicate. What I want is to capture the traffic (communication of the two Pi's) from my PC . The problem is that when I use Wireshark on my PC, I can't see the traffic generated from s.send() and conn.sendall() between the two Pi's, I'm still a student and not very advanced in Networking so I'm not sure if this problem is related to Raspberry Pi, Networking or Wireshark.

This is the code for the first Raspberry Pi (Server)

import socket

host = ''
port = 5560

storedValue = "Yo, what's up?"

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(1)
conn, address = s.accept()
print("Connected to: " + address[0] + ":" + str(address[1]))

while True:
        data = conn.recv(1024) # receive the data
        data = data.decode('utf-8')
        dataMessage = data.split(' ', 1)
        command = dataMessage[0]
        reply = storedValue
        s.close()
        conn.sendall(str.encode(reply))

conn.close()

This is for the second Raspberry Pi (Client)

import socket

host = '192.168.2.2'
port = 5560

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))

while True:
    command = input("Enter you command: ")
    s.send(str.encode(command))
    reply = s.recv(1024)
    print(reply.decode('utf-8'))
s.close()

You could use your PC as a proxy.

The client send its data to the proxy (which runs on your PC) and the proxy sends it to the server. Later the proxy receives the answer from the server and sends it back to the client.

You could look into this proxy, pyproxy , for example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM