-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathudp-msg-receiver.py
More file actions
67 lines (49 loc) · 1.68 KB
/
udp-msg-receiver.py
File metadata and controls
67 lines (49 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
#Created by PepeBigotes
import os, ctypes
try: is_admin = (os.getuid() == 0)
except AttributeError: is_admin = (ctypes.windll.shell32.IsUserAnAdmin() != 0)
if not is_admin:
print("[!] You need root/admin priviledges to run this script")
print(" Forgot to use sudo?")
exit()
try: from scapy.all import *
except ImportError:
print("[!] You need to have Scapy installed to run this script")
print(" Try 'pip3 install scapy' or 'sudo apt install python3-scapy'")
exit()
from time import sleep
os.system('cls' if os.name=='nt' else 'clear')
print("""\
_ _
_ _ _| |___ _____ ___ ___ ___ ___ ___ ___|_|_ _ ___ ___
| | | . | . | | |_ -| . | | _| -_| _| -_| | | | -_| _|
|___|___| _| |_|_|_|___|_ | |_| |___|___|___|_|\_/|___|_|
|_| |___|
""")
try:
LOCAL_IP = get_if_addr(conf.iface)
print(f"Host: {LOCAL_IP}")
PORT = int(input("Port: "))
except KeyboardInterrupt:
print("\n\nKeyboardInterrupt")
exit()
def handle_pkt(pkt):
if not pkt.haslayer(IP): return
if not pkt.haslayer(UDP): return
if pkt[UDP].dport != PORT: return
payload = bytes(pkt[UDP].payload)
try: msg_utf8 = payload.decode("utf-8")
except UnicodeDecodeError: pass
if msg_utf8:
src = pkt[IP].src
print(f"[{src}] {msg_utf8}")
sniffer = AsyncSniffer(filter="udp", prn=handle_pkt, store=0)
sniffer.start()
print(f"\nListening for UDP messages on port {PORT}, press CTRL+C to stop")
try:
while True: sleep(1)
except KeyboardInterrupt:
print("\nKeyboardInterrupt")
sniffer.stop()
exit()