Gorcupt

444

Apr 4th, 2022
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. from cmath import pi
  2. import socket
  3. from pythonping import ping
  4. import threading
  5. import socket
  6. import time
  7.  
  8. addresses = []
  9. pings = {}
  10.  
  11. def getMyIp():
  12. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  13. s.connect(("8.8.8.8", 80))
  14. ip = s.getsockname()[0]
  15. s.close()
  16. return ip
  17.  
  18. def scan_Ip(ip):
  19. address = str(net) + str(ip)
  20. p = ping(address).rtt_avg_ms
  21. if p != 2000:
  22. addresses.append(address)
  23. pings[address] = p
  24. print("address: " + address + " ping: " + str(p))
  25.  
  26. net = getMyIp()
  27. print('You IP :',net)
  28. net_split = net.split('.')
  29. a = '.'
  30. net = net_split[0] + a + net_split[1] + a + net_split[2] + a
  31. start_point = 1
  32. end_point = 255
  33.  
  34. for ip in range(start_point, end_point):
  35. if ip == int(net_split[3]):
  36. continue
  37. potoc = threading.Thread(target=scan_Ip, args=[ip])
  38. potoc.start()
  39.  
  40. potoc.join()
  41.  
  42. import graphviz
  43.  
  44. dot = graphviz.Digraph(comment="MyNet")
  45.  
  46. myIp = str(getMyIp())
  47.  
  48. dot.node(myIp,'Me: ' + myIp)
  49.  
  50. for address in addresses:
  51. p = str(pings[address])
  52. dot.node(address, address)
  53. dot.edge(myIp, address, p)
  54.  
  55. print(dot.source)
  56.  
  57. import os
  58. os.environ["PATH"] += os.pathsep + 'E:/Python/Lib/site-packages/graphviz/'
  59.  
  60. dot.render('./MyNet.gv').replace('\\', '/')
  61.  
  62. dot.render('./MyNet.gv', view=True)
  63.  
  64. print(ping('192.168.12.136'))
Advertisement
Add Comment
Please, Sign In to add comment