Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Antonio Villanueva
- Net shark
- Rechercher des périphériques réseau et trouve leur adresse IP
- comme
- nmap -T4 -sP ip1.ip2.ip3.ip4/24
- dépendances
- pip3 install zeroconf
- Note:
- Dans les anciennes versions, self.service_info.addresses[0]
- devient
- self.service_info.address
- """
- #!/usr/bin/python3
- # -*- coding: utf-8
- import socket
- from zeroconf import ServiceBrowser, ServiceListener, Zeroconf
- class MyListener(ServiceListener):
- def __init__(self):
- self.service_info = None
- def update_service(self, zc: Zeroconf, type_: str, name: str) -> None:
- print(f"Service {name} updated")
- def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None:
- print(f"Service {name} removed")
- def add_service(self, zc: Zeroconf, type_: str, name: str) -> None:
- """ montre le périphérique réseau et son adresse IP """
- self.service_info = zc.get_service_info(type_, name)
- ip = socket.inet_ntoa(self.service_info.addresses[0])
- print( f" {name} : {ip}")
- if __name__ == "__main__":
- zeroconf = Zeroconf()
- listener = MyListener()
- browser = ServiceBrowser(zeroconf, "_http._tcp.local.", listener)
- try:
- input("Enter pour sortir...\n\n")
- finally:
- zeroconf.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement