filename ) else : # No error print ( "Data saved into file " + my_scan. write_file () # Error while writting the file? if res : # Yes print ( "Write error with file " + my_scan. nbr_host_found )) # Write the file on disk res = my_scan. list_of_hosts_found : print ( i ) # Display information print ( "Number of hosts found: " + str ( my_scan. run () # Display information print ( "List of hosts found:" ) # Display the IP address of all the hosts found for i in my_scan. nbr_host )) # Run the network scan print ( "Scanning hosts." ) # Run the scan of hosts using pings my_scan. prefixlen )) print ( "Number of hosts to scan: " + str ( my_scan. network )) print ( "Prefix to scan: " + str ( my_scan. Networkscan ( my_network ) # Display information print ( "Network to scan: " + str ( my_scan. Python script: #!/usr/bin/env python3 # Import Python library import networkscan # Main function if _name_ = '_main_' : # Define the network to scan my_network = "192.168.0.0/24" # Create the object my_scan = networkscan. Write_file() method accepts two optional parameters: def write_file ( self, file_type = 0, filename = "hosts.yaml" ): """ Method to write a file with the list of the detected hosts """ # Input: # - file_type (integer, optional): 0, Nornir file (default value) # 1, Text file as output file # - filename (string, optional): the name of the file to be written ("hosts.yaml" # is the default value) # Ouput: # A text file with the list of detected hosts ("hosts.yaml" is the default value) # return 0 if no error occured This script scans a network then it creates a yaml file with the list of hosts found. run () # Display the IP address of all the hosts found for i in my_scan. Networkscan ( my_network ) # Run the scan of hosts using pings my_scan. The following script just scan a network then displays the list of host found. Hosts.yaml: - device1 : hostname : 192.168.0.1 groups : - device_discovered device2 : hostname : 192.168.0.100 groups : - device_discovered device3 : hostname : 192.168.0.101 groups : - device_discovered device4 : hostname : 192.168.0.10 groups : - device_discovered device5 : hostname : 192.168.0.11 groups : - device_discovered device6 : hostname : 192.168.0.12 groups : - device_discovered device7 : hostname : 192.168.0.111 groups : - device_discovered ![]() With the command "networkscan.py 192.168.0.0/23 -m -w foo.yaml" you do create a file named "foo.yaml". Please note that when no file is specified with the parameter "-w" then a "hosts.yaml" file is created by default. networkscan.py 192.168.0.0/25 -q >inventory.txtĤ - How to scan a /23 network then save the list of hosts into a yaml file compatible with Nornir syntax (mute mode and creation of a yaml file) networkscan.py 192.168.0.0/28 -qĤ - How to scan a /25 network then to save the list of hosts into a text file (quiet mode and redirection of the output into a file) ![]() Number of hosts found: 7 (project1 ) python ]$ģ - How to scan a /28 network displaying just the name of the hosts (quiet mode) m Mute mode (nothing is displayed on screen ) -q Quiet mode (just the list of hosts found is displayed ) -w Write a yaml host file with an optional filename (default name is hosts.yaml ) (project1 ) python ]$ Here are the available options for the software: (project1 ) python ]$. Networkscan requires python 3 and the following python libraries:
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |