Network Connectivity Testing Tools

This article show how to craft network connectivity testing tools to test and analyze the working of a remote system at different layers of the OSI model like Layer 2 , layer 3. Scapy tool is used to demonstrate the working

Layer 2 testing

Devices send ARP packets to discover the mac-address of a device at layer 2. If the ARP response is not received, the system may be shutdown or unavailable at that point of time. For this , we craft an ARP request and send it to the intended recipient and analyze if the response is received or not. The script is shown below.

arp=ARP()
arp.hwdst=’00:00:00:00:00:00′
arp.pdst=’192.168.1.100′
arp.hwsrc=’00:E2:4F:C9:AE:EB’
arp.psrc=’192.168.1.20′
ether=Ether()
ether.dst=’FF:FF:FF:FF:FF:FF’
ether.src=’00:E2:4F:C9:AE:EB’
srp(ether/arp)
Begin emission:
Finished to send 1 packets.
Received 1 packets, got 1 answers, remaining 0 packets

The above code creates an ARP request packet from the IP address 192.168.1.20 to 192.168.1.100. The ARP packet is encapsulated in an Ethernet header which has the destination mac-address as FF-FF-FF-FF-FF-FF which is a broadcast for ARP request packets. The packet is send using the command srp(ether/arp). It can be observed that a response to the packet is received indicating that the remote system is up at layer 2.

——————————————————————————————————————-
Learn to make custom tools and scripts with our video course – Python Network programming
——————————————————————————————————————-

Layer 3 testing

ip=IP()
icmp=ICMP()
icmp.type=8
icmp.code=0
ip.src=’192.168.1.20′
ip.dst=’192.168.1.100′
sr(ip/icmp)
Received 3 packets, got 1 answers, remaining 0 packets

The above code creates a ping packet with ICMP type as 8 and code as 0. The goal is to test if the system 192.168.1.100 is reachable at layer 3 from 192.168.1.20. ICMP is a layer 3 protocol, which is used by ping. It cane be observed that the response has been received indicating that the device is up at layer 3.

——————————————————————————————————————-
Become a packet crafting expert with our video course – Python Network programming
——————————————————————————————————————-