mpscan00.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import socket
  2. import socks
  3. class cyConn():
  4. oPorts = []
  5. services = []
  6. result = []
  7. proxyHost = "127.0.0.1"
  8. proxyPort = 9050
  9. def __init__(self):
  10. prxConn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  11. try:
  12. prxConn.connect((self.proxyHost, self.proxyPort))
  13. except:
  14. exit("proxy connection error")
  15. socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, self.proxyHost, self.proxyPort, True)
  16. self.sock = socks.socksocket()
  17. def isOn(self):
  18. socket.socket = socks.socksocket
  19. self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  20. try:
  21. self.socket.sendto((self.target, 7))
  22. return True
  23. except:
  24. return False
  25. def tcpConn(self, port):
  26. socket.socket = socks.socksocket
  27. TCPsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  28. TCPsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  29. TCPsock.settimeout(2.0)
  30. try:
  31. #if self.isOn():
  32. TCPsock.connect((self.target, port))
  33. #self.services.append(TCPsock.getservbyport(port, 'tcp'))
  34. return True
  35. except:
  36. return None
  37. def mpScan(self, target, port=None, prange=None):
  38. if not port and not prange or not target:
  39. return "function usage: mpScan((string) target, (int) port or (list) range))"
  40. self.target = target
  41. if prange and port is None:
  42. for p in prange:
  43. print(p)
  44. if self.tcpConn(p):
  45. self.oPorts.append(p)
  46. elif port and prange is None:
  47. if self.tcpConn(port):
  48. self.oPorts.append(port)
  49. else:
  50. return "function usage: mpScan((string) target, (int) port or (list) range))"
  51. self.result = [self.oPorts, self.services]
  52. return self.result
  53. c = cyConn()
  54. r = c.mpScan(target="137.74.187.102", prange=[80, 443, 8080])
  55. print("rslt =\n\t{}".format(r))