• Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
  • Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Creating a csv host import from a network scan

Scheduled Pinned Locked Moved
Tutorials
1
1
1.3k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J
    JJ Fullmer Testers
    last edited by JJ Fullmer Feb 17, 2017, 9:14 AM Feb 17, 2017, 3:14 PM

    Run the following code in powershell (after editing it with your network’s subnets) to create a csv that will import all hosts on your network.

    # examples, just gotta put subnets minus the final .x in a string array
    # Could also be params if this was a function
    $subnets = @("192.168.1", "192.168.2", "10.2.114", "192.168.0"); 
    $subnets | ForEach-Object { # loop through each subnet
    	for ($i=0; $i -lt 255; $i++) { # loop through 0 to 255 of the subnet
    		$hn = nslookup "$_.$i"; # run nslookup on the current ip in the loop
    		if ($hn[3] -ne $null -AND $hn[3] -ne "") { # does the ip have a dns entry
    			$hostN = $hn[3].Replace("Name:","").Trim(); # parse the nslookup output into a fqdn host name
    			$mac = getMac /S $hostN; # does the hostname have a mac addr. Can also add /U and /P for user and password if not running from a administrative account
    			if ($mac -ne $null) { # was there a mac for the host?
    				$macAddr = $mac[3].Split(' ')[0]; # use the first found mac address and parse it
    				"$hostN,$macAddr" | Out-File C:\hosts.csv -Append -Encoding UTF8; # add the hostname,macaddress to the csv
    			}
    		}
    	}
    }
    

    Have you tried the FogApi powershell module? It's pretty cool IMHO
    https://github.com/darksidemilk/FogApi
    https://fogapi.readthedocs.io/en/latest/
    https://www.powershellgallery.com/packages/FogApi
    https://forums.fogproject.org/topic/12026/powershell-api-module

    1 Reply Last reply Reply Quote 4
    • J JJ Fullmer referenced this topic on Jul 19, 2024, 6:25 PM
    • 1 / 1
    1 / 1
    • First post
      1/1
      Last post

    221

    Online

    12.0k

    Users

    17.3k

    Topics

    155.2k

    Posts
    Copyright © 2012-2024 FOG Project