How to catch CRC errors on a live LAN connection?

I’m an undergrad and new to python. For one of my projects I’m in need to build a program to find CRC errors on a live LAN connection. I searched it already but only got programs for builder and sender type of programs. But since they can’t be used on a live connection I can’t take them. If anyone can please guide me to do this, it will be really appreciated and helpful.

You want to look into network traffic capture. One of the most popular tools is libpcap (used by tcpdump, nmap, Wireshark…)

In Python you have libpcap bindings (interface to the C language library) available:

Regarding “CRC errors” I hope you mean checksum errors in layers 3 and above. AFAIK normal network cards always discard frames with invalid checksum and this functionality cannot be overridden.

I just need to get the count of the CRC error. I know switches take the CRC error count(CRC errors in lower layers). So, in such way can I do that using libcap. I saw sender and receiver programs which uses predefined keys. but I need to do this on a live LAN connection I guess I have to go through the negotiation process as well

That is something very different! A network card driver counts the checksum errors (and other errors) for you. You just need to read the value. Just keep in mind that it is a single counter on a network interface. You will not be able to distinguish the communicating addresses not say connections!

You want to look into tools which can read the counters. You can use for example:

  • CLI tools like ip or ethtool (we are talking about Ethernet, right?)
  • The kernel interface like /sys/class/net/eth0/statistics/rx_crc_errors
  • monitoring tools like SNMP (you will need to run a SNMP daemon on the computer)

yeah that’s true. what I need is, build a python program to read that counter. from what you said, there are 2 ways i guess. first one is reading the counter in local interface and the second one is doing SNMP polls to the partnered switch to get the counter. what is easier? and how to do it? if you can provide me references and guides that will be really appreciated.

I think the easiest option is to read the files from the sysfs file system of the Linux kernel.

You read them as regular text files. Here are tutorials:

https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files