Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- from subprocess import check_output
- from scapy.all import *
- def Os():
- platform = sys.platform
- if platform == 'linux':
- print(f"The machine is on {platform}")
- elif platform == 'win32':
- print(f"The machine is on {platform}")
- else:
- print("Don't know what the platform is")
- version = sys.version[:5]
- print(f"The version of python is {version}")
- def found_network():
- address = subprocess.check_output("ip route | grep / | cut -c1-15",shell=True) #Permet d'avoir l'@network/mask
- address = address.decode('ascii')
- [address] = address.splitlines()
- address = str(address)
- return address
- def scan_network(address):
- packet = Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=address)
- result = srp(packet, timeout=3, verbose=0)[0]
- clients_ip = []
- clients_mac = []
- for sent, response in result:
- clients_ip.append({"ip": response.psrc})
- clients_mac.append({"mac": response.hwsrc})
- if len(clients_ip) == 0: #j'ai debug un peu et je pense que la pb vien de la variable packet
- print("liste vide")
- else:
- print(clients_ip)
- with open("ip_address.txt","w",encoding='utf-8') as file:
- for clients in clients_ip:
- file.write(str("{}".format(clients['ip'])))
- file.write("\n")
- with open("mac_address.txt","w",encoding='utf-8') as f:
- for clients in clients_mac:
- f.write(str("{}".format(clients['mac'])))
- f.write("\n")
- def main():
- addr = found_network()
- print(addr)
- scan_network(addr)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement