Monitor network traffic while running a python script

Viewed 1283

I am trying to monitor network traffic coming in and out of my VM**. My VM is connected to a socket via TCP (IP, PORT) with the python socket library. Once connected, I am sending a stream of bytes to the socket and then close the connection. The VM runs Ubuntu 18.04 LTS. The connection is made in a VPN tunnel.

How do I capture the traffic for the source and destination while my python script runs? I have tried to work with scapy and Wireshark/pyshark, but the documentation I found did not help me a lot.

Does anyone have an idea how I could do this? I am using python 3

1 Answers

I use wireshark to capture packets, you can filter out the destination and source (as flags to), here's the docs. Is the VPN using some kind of security to encrypt information (such as TLS)?

In the filter insert:

ip.src==your.local.ip.addr && ip.dst==your.VM.ip.addr && ip.proto=="TCP"

What could happen is that the VM tries to get updates and wireshark can pickup a lot of packets, it can mess up your search for the information in the sockets (byte stream).

You also can try stop some Ubuntu services to prevent the internet use, but I cant tell you how to disable all.

Do you want to pickup that byte stream with a sniffer and convert into a person's eye?

If that's the case, it is advanced stuff I can't explain.

Hope I could help.

Related