Created
October 28, 2011 04:49
-
-
Save btoews/1321649 to your computer and use it in GitHub Desktop.
portscanner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Python logic for portscanner. Just plug in a wee bit of scapy and it should work like a charm. | |
#I golfed down some of the CIDER stuff, but it could use more. | |
#(c)mastahyeti | |
import argparse | |
import random | |
default_sport = [80,443,123] | |
default_saddr = ["192.168.1.1"] | |
def parse_list(string): | |
if not string: | |
return string | |
elif not not string.count('-'): | |
if string.count('.'): | |
raise Exception("Please specify IP address ranges using CIDR (192.168.0.1/24)") | |
r = [int(i) for i in string.split('-')] | |
output = range(r[0],r[1]+1) | |
elif not not string.count(','): | |
try: | |
output = [int(i) for i in string.split(',')] | |
except ValueError: | |
output = [parse_list(i) for i in string.split(',')] | |
elif string.count('/'): | |
addr,mask = string.split('/') | |
netmask = (2**int(mask)-1) << (32 - int(mask)) | |
wildcardmask = netmask ^ 2**32-1 | |
addr = [int(i) for i in addr.split('.')] | |
int_addr = 0 | |
for i in range(0,4): | |
int_addr += addr[i] << ((3-i)*8) | |
int_output = [(int_addr & netmask) + i for i in range(0,wildcardmask+1)] | |
output = ['.'.join([str(int_addr >> (3-x) * 8 & 0xFF) for x in range(0,4)]) for int_addr in int_output] | |
else: | |
output = [int(string)] | |
return output | |
if __name__ == "__main__": | |
dest = [] | |
src = [] | |
dports=[] | |
sports=[] | |
parser = argparse.ArgumentParser(description = 'Scan some ports... Fuck some IDSs') | |
parser.add_argument('-s',metavar='source_ip',help='IP Address(es) to scan from (single, comma separated list, or slash notated CIDR address)',required=True) | |
parser.add_argument('-d',metavar='destination_ip',help='IP Address(es) to scan (single, comma separated list, or slash notated CIDR address)',required=True) | |
parser.add_argument('-S',metavar='source_ports',help='TCP port(s) to scan from (single, comma separated, or range in form 80-120)') | |
parser.add_argument('-D',metavar='destination_ports',help='TCP port(s) to scan (single, comma separated, or range in form 80-120)',required=True) | |
args = parser.parse_args() | |
saddr = parse_list(args.s) | |
saddr = saddr if saddr else default_saddr | |
daddr = parse_list(args.d) | |
sport = parse_list(args.S) | |
sport = sport if sport else default_sport | |
dport = parse_list(args.D) | |
for da in daddr: | |
for dp in dport: | |
sa = saddr[random.randint(0,len(saddr)-1)] | |
sp = sport[random.randint(0,len(sport)-1)] | |
print "\ | |
Source Address: %s\n\ | |
Source Port: %d\n\ | |
Destination Address: %s\n\ | |
Destination Port: %d\n\n"%\ | |
(sa,\ | |
sp,\ | |
da,\ | |
dp) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment