This Blog is basically published first in my blog ankitdobhal.github.io
Let's try to travel the time 1 year back when I started to learn about little bit about hacking and networking in windows and Linux. Ping was my first tool,it is a basic networking utility which helps to check connectivity and communication b/w two systems.So When first time I used this utility it helped me to understand the basic concept of packets,and I was very much happy. well I know its sound to much awkward now.
Well!! Then after spending my more time in pentesting, I started to automate more stuff using python. yesterday ping came back to me, when I was working and trying to understand how packets works, & found one of the module of the python scapy and tried to break the code & ping the network,lets try to understnd what I did with with scapy.
So before discussing about scapy you need to be able that how to write code in python ,& if you don't know then this place is not for you!! Now What is Scapy and how it works?
Well scapy is a powerful Python-based interactive packet manipulation program and library.It is able to forge or decode packets of a wide number of protocols, send them on the wire, capture them, store or read them using pcap files, match requests and replies, and much more. It is designed to allow fast packet prototyping by using default values that work.
To install this super amazing python based library & tool you need to write this following commands in your os terminal:
pip install scapy (Windows) pip3 install scapy (Linux)
#!/usr/bin/python3 #pingscanner.py import sys from scapy.all import * print("pinging the target....") ip = sys.argv # command line argument icmp = IP(dst=ip)/ICMP() #IP defines the protocol for IP addresses #dst is the destination IP address #TCP defines the protocol for the ports resp = sr1(icmp,timeout=10) if resp == None: print("This host is down") else: print("This host is up")
Python have its power to automate most of the stuffs which lets the pentester to ease their hacking task,In above code the basic first thing I did imported scapy and sys module to use them their functions,ip is the variable which stores the target ip address ,icmp variable which creates packet and resp variable which contain sr1 function that Send packets at layer 3 and return only the first answer.Then finally conditional statement to check host is up or down.