from gevent import monkey monkey patch_all import logging import geven

 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
from gevent import monkey
monkey.patch_all()
import logging
import gevent
from scapy.all import sr1, IP, ICMP, RandShort, send, TCP
SYNACK = 0x12
RSTACK = 0x14
# ping = sr1(IP(dst='8.8.8.9')/ICMP())
def setup_logging():
for hdl in logging.getLogger().handlers:
hdl.setFormatter(logging.Formatter(
'[%(levelname)s] %(name)s: %(message)s'
))
# WTF
#for hdl in logging.getLogger('scapy.runtime').handlers:
# hdl.setFormatter(logging.Formatter(
# '[%(levelname)s] %(name)s: %(message)s'
# ))
def main(**kwargs):
setup_logging()
#target_ip = '8.8.8.8'
target_ip = '212.47.229.127'
target_port = 80
with gevent.Timeout(2):
sport = RandShort()
syn_pkt = sr1(
IP(dst=target_ip)
/ TCP(sport=sport, dport=target_port, flags='S')
)
flags = syn_pkt.getlayer(TCP).flags
if flags == SYNACK:
print('Port is open!')
else:
print('Port is not open!')
rst_pkt = (
IP(dst=target_ip)
/ TCP(sport=sport, dport=target_port, flags='R')
)
send(rst_pkt)