• 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.
    • JJ FullmerJ
      JJ Fullmer Testers
      last edited by JJ Fullmer

      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
      • JJ FullmerJ JJ Fullmer referenced this topic on
      • 1 / 1
      • First post
        Last post

      163

      Online

      12.0k

      Users

      17.3k

      Topics

      155.2k

      Posts
      Copyright © 2012-2024 FOG Project