Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. import os
  2. import sys
  3. from subprocess import check_output
  4. from scapy.all import *
  5.  
  6.  
  7. def Os():
  8.  
  9. platform = sys.platform
  10.  
  11. if platform == 'linux':
  12. print(f"The machine is on {platform}")
  13. elif platform == 'win32':
  14. print(f"The machine is on {platform}")
  15. else:
  16. print("Don't know what the platform is")
  17.  
  18. version = sys.version[:5]
  19. print(f"The version of python is {version}")
  20.  
  21.  
  22. def found_network():
  23. address = subprocess.check_output("ip route | grep / | cut -c1-15",shell=True) #Permet d'avoir l'@network/mask
  24. address = address.decode('ascii')
  25. [address] = address.splitlines()
  26. address = str(address)
  27. return address
  28.  
  29.  
  30. def scan_network(address):
  31.  
  32. packet = Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=address)
  33. result = srp(packet, timeout=3, verbose=0)[0]
  34.  
  35. clients_ip = []
  36. clients_mac = []
  37.  
  38.  
  39.  
  40. for sent, response in result:
  41. clients_ip.append({"ip": response.psrc})
  42. clients_mac.append({"mac": response.hwsrc})
  43.  
  44.  
  45. if len(clients_ip) == 0: #j'ai debug un peu et je pense que la pb vien de la variable packet
  46. print("liste vide")
  47. else:
  48. print(clients_ip)
  49.  
  50.  
  51.  
  52. with open("ip_address.txt","w",encoding='utf-8') as file:
  53. for clients in clients_ip:
  54. file.write(str("{}".format(clients['ip'])))
  55. file.write("\n")
  56.  
  57. with open("mac_address.txt","w",encoding='utf-8') as f:
  58. for clients in clients_mac:
  59. f.write(str("{}".format(clients['mac'])))
  60. f.write("\n")
  61.  
  62. def main():
  63. addr = found_network()
  64. print(addr)
  65. scan_network(addr)
  66.  
  67.  
  68. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement