From 26ae2e577f401e4fb7c23de45966d33a727e7ea8 Mon Sep 17 00:00:00 2001 From: n1nj4sec Date: Tue, 19 Jan 2016 20:15:11 +0100 Subject: [PATCH] portscan dependency --- pupy/packages/all/portscan.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 pupy/packages/all/portscan.py diff --git a/pupy/packages/all/portscan.py b/pupy/packages/all/portscan.py new file mode 100644 index 00000000..5b185cd3 --- /dev/null +++ b/pupy/packages/all/portscan.py @@ -0,0 +1,29 @@ +# -*- coding: UTF8 -*- +# Copyright (c) 2015, Nicolas VERDIER (contact@n1nj4.eu) +# Pupy is under the BSD 3-Clause license. see the LICENSE file at the root of the project for the detailed licence terms +from scapy.all import * + +def format_response(pkt): + res="" + if "R" in pkt.sprintf("%TCP.flags%"): + res+="TCP/{:<7} closed {}".format(pkt[TCP].sport, pkt.sprintf("{TCP:%TCP.flags%}{ICMP:%IP.src% - %ICMP.type%}")) + elif pkt.sprintf("%TCP.flags%")=="SA": + res+="TCP/{:<7} open {}".format(pkt[TCP].sport, pkt.sprintf("{TCP:%TCP.flags%}{ICMP:%IP.src% - %ICMP.type%}")) + else: + res+="TCP/{:<7} filtered {}".format(pkt[TCP].sport, pkt.sprintf("{TCP:%TCP.flags%}{ICMP:%IP.src% - %ICMP.type%}")) + return res+"\n" + +class PortScanner(object): + def __init__(self): + pass + def scan(self, address, ports, timeout=4, iface=None): + res="" + ans,unans=sr(IP(dst=address)/TCP(flags="S",dport=list(ports)), verbose=False, iface=iface, timeout=timeout) + for req,resp in ans: + res+=format_response(resp) + return res +if __name__=='__main__': + p=PortScanner() + print p.scan("192.168.2.133",[443,80,22]) + +