Advertisement
opexxx

portscanner.py

Aug 18th, 2014
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.36 KB | None | 0 0
  1. #Python logic for portscanner. Just plug in a wee bit of scapy and it should work like a charm.
  2. #I golfed down some of the CIDER stuff, but it could use more.
  3. #(c)mastahyeti
  4.  
  5. import argparse
  6. import random
  7.  
  8. default_sport = [80,443,123]
  9. default_saddr = ["192.168.1.1"]
  10. def parse_list(string):
  11. if not string:
  12. return string
  13. elif not not string.count('-'):
  14. if string.count('.'):
  15. raise Exception("Please specify IP address ranges using CIDR (192.168.0.1/24)")
  16. r = [int(i) for i in string.split('-')]
  17. output = range(r[0],r[1]+1)
  18. elif not not string.count(','):
  19. try:
  20. output = [int(i) for i in string.split(',')]
  21. except ValueError:
  22. output = [parse_list(i) for i in string.split(',')]
  23. elif string.count('/'):
  24. addr,mask = string.split('/')
  25. netmask = (2**int(mask)-1) << (32 - int(mask))
  26. wildcardmask = netmask ^ 2**32-1
  27. addr = [int(i) for i in addr.split('.')]
  28. int_addr = 0
  29. for i in range(0,4):
  30. int_addr += addr[i] << ((3-i)*8)
  31. int_output = [(int_addr & netmask) + i for i in range(0,wildcardmask+1)]
  32. output = ['.'.join([str(int_addr >> (3-x) * 8 & 0xFF) for x in range(0,4)]) for int_addr in int_output]
  33. else:
  34. output = [int(string)]
  35. return output
  36.  
  37. if __name__ == "__main__":
  38. dest = []
  39. src = []
  40. dports=[]
  41. sports=[]
  42. parser = argparse.ArgumentParser(description = 'Scan some ports... Fuck some IDSs')
  43. 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)
  44. parser.add_argument('-d',metavar='destination_ip',help='IP Address(es) to scan (single, comma separated list, or slash notated CIDR address)',required=True)
  45. parser.add_argument('-S',metavar='source_ports',help='TCP port(s) to scan from (single, comma separated, or range in form 80-120)')
  46. parser.add_argument('-D',metavar='destination_ports',help='TCP port(s) to scan (single, comma separated, or range in form 80-120)',required=True)
  47. args = parser.parse_args()
  48. saddr = parse_list(args.s)
  49. saddr = saddr if saddr else default_saddr
  50. daddr = parse_list(args.d)
  51. sport = parse_list(args.S)
  52. sport = sport if sport else default_sport
  53. dport = parse_list(args.D)
  54.  
  55. for da in daddr:
  56. for dp in dport:
  57. sa = saddr[random.randint(0,len(saddr)-1)]
  58. sp = sport[random.randint(0,len(sport)-1)]
  59. print "\
  60. Source Address: %s\n\
  61. Source Port: %d\n\
  62. Destination Address: %s\n\
  63. Destination Port: %d\n\n"%\
  64. (sa,\
  65. sp,\
  66. da,\
  67. dp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement