Skip to content

Commit 83a5d14

Browse files
committed
add crafting packets scapy tutorial
1 parent 25d764e commit 83a5d14

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
1818
- [How to Inject Code into HTTP Responses in the Network in Python](https://www.thepythoncode.com/article/injecting-code-to-html-in-a-network-scapy-python). ([code](scapy/http-code-injector/))
1919
- [How to Perform IP Address Spoofing in Python](https://thepythoncode.com/article/make-an-ip-spoofer-in-python-using-scapy). ([code](scapy/ip-spoofer))
2020
- [How to See Hidden Wi-Fi Networks in Python](https://thepythoncode.com/article/uncovering-hidden-ssids-with-scapy-in-python). ([code](scapy/uncover-hidden-wifis))
21+
- [Crafting Dummy Packets with Scapy Using Python](https://thepythoncode.com/article/crafting-packets-with-scapy-in-python). ([code](scapy/crafting-packets))
2122
- [Writing a Keylogger in Python from Scratch](https://www.thepythoncode.com/article/write-a-keylogger-python). ([code](ethical-hacking/keylogger))
2223
- [Making a Port Scanner using sockets in Python](https://www.thepythoncode.com/article/make-port-scanner-python). ([code](ethical-hacking/port_scanner))
2324
- [How to Create a Reverse Shell in Python](https://www.thepythoncode.com/article/create-reverse-shell-python). ([code](ethical-hacking/reverse_shell))

Diff for: scapy/crafting-packets/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [Crafting Dummy Packets with Scapy Using Python](https://thepythoncode.com/article/crafting-packets-with-scapy-in-python)

Diff for: scapy/crafting-packets/network_latency_measure.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
server_ips = ["192.168.27.1", "192.168.17.129", "192.168.17.128"]
2+
3+
from scapy.all import IP, ICMP, sr1
4+
import time
5+
6+
def check_latency(ip):
7+
packet = IP(dst=ip) / ICMP()
8+
start_time = time.time()
9+
response = sr1(packet, timeout=2, verbose=0)
10+
end_time = time.time()
11+
12+
if response:
13+
latency = (end_time - start_time) * 1000 # Convert to milliseconds
14+
print(f"[+] Latency to {ip}: {latency:.2f} ms")
15+
else:
16+
print(f"[-] No response from {ip} (possible packet loss)")
17+
18+
for server_ip in server_ips:
19+
check_latency(server_ip)
20+
21+

Diff for: scapy/crafting-packets/packet_craft.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Uncomment them and run according to the tutorial
2+
#from scapy.all import IP, TCP, send, UDP
3+
4+
# # Step 1: Creating a simple IP packet
5+
# packet = IP(dst="192.168.1.1") # Setting the destination IP
6+
# packet = IP(dst="192.168.1.1") / TCP(dport=80, sport=12345, flags="S")
7+
# print(packet.show()) # Display packet details
8+
# send(packet)
9+
10+
11+
############
12+
# from scapy.all import ICMP
13+
14+
# # Creating an ICMP Echo request packet
15+
# icmp_packet = IP(dst="192.168.1.1") / ICMP()
16+
# send(icmp_packet)
17+
18+
19+
############
20+
# from scapy.all import UDP
21+
22+
# # Creating a UDP packet
23+
# udp_packet = IP(dst="192.168.1.1") / UDP(dport=53, sport=12345)
24+
# send(udp_packet)
25+
26+
27+
28+
###########
29+
# blocked_packet = IP(dst="192.168.1.1") / TCP(dport=80, flags="S")
30+
# send(blocked_packet)
31+
32+
# allowed_packet = IP(dst="192.168.1.1") / UDP(dport=53)
33+
# send(allowed_packet)
34+

Diff for: scapy/crafting-packets/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scapy

0 commit comments

Comments
 (0)