-
Notifications
You must be signed in to change notification settings - Fork 6
/
ICMPping.py
65 lines (50 loc) · 1.58 KB
/
ICMPping.py
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
#!/usr/bin/env python
import argparse
import signal
from sys import exit
from scapy.layers.inet import IP, ICMP, sr, conf
def keyboard_interrupt_handler(interrupt_signal, frame):
"""
Keyboard (CTRL + C) interrupt function
"""
print("Ping stopped")
print("KeyboardInterrupt ID: {} {} has been caught.".format(interrupt_signal, frame))
exit(1)
def icmp_ping():
"""
Ping function
"""
global interface
global network
conf.iface = interface
conf.verb = 1
ans, uans = sr(IP(dst=network)/ICMP())
ans.summary(lambda s, r: r.sprintf("%IP.src% is alive"))
def run_app():
"""
Main function to parse arguments and run
"""
global interface
global network
description = 'Simple ICMP ping'
epilog = 'The author of this code take no responsibility for your use or misuse'
parser = argparse.ArgumentParser(prog='ICMPping.py', description=description, epilog=epilog)
parser.add_argument("interface", help="Your interface")
parser.add_argument("network", help="Your target ip")
args = parser.parse_args()
if len(args.interface) < 1:
print('You did not provide any interface?')
exit(1)
else:
interface = args.interface
if len(args.network) < 1:
print('You did not provide any ip range?')
exit(1)
else:
network = args.network
print("Start ICMP ping on interface {} on network {}".format(interface, network))
icmp_ping()
if __name__ == "__main__":
interface = network = None
signal.signal(signal.SIGINT, keyboard_interrupt_handler)
run_app()