15

This question arises from trying to manage my home wifi network. I've been toying with commands such as get-netipaddress, ipconfig and nslookup.exe.

The following command has kind of led me somewhere but it doesn't have the information that i'm looking for.

Get-NetIPAddress | Format-Table

I would like to be able to get a list of all devices on my home network. Including the device ip address, and some sort of name for that device. The previous command gives an ipaddress but it looks more like a mac address? Any help is appreciated!

2
  • 1
    This sounds like something your router should have. Your computer might not see everthing on your home network
    – Matt
    Jan 22, 2017 at 0:26
  • Have you considered usin nmap? Jan 22, 2017 at 14:25

5 Answers 5

23

I converted my batch tool for this into a Powershell script.
It is a wrapper for the cmd line tools ping.exe, arp.exe and nslookup.exe.

  • To get good results all devices should be switched on and connected.
  • To get all possible DeviceIPs into the arp cache of your computer,
    a ping to all IPs in a presumed /24 subnet is executed in advance.
  • Arp.exe -a will return the IP and MAC.
  • Nslookup.exe is used to find the Name stripped from any local domain suffix.

Edit the var $SubNet to fit your environment.

## Q:\Test\2017\01\21\SO_41785413.ps1
$FileOut = ".\Computers.csv"
## Ping subnet
$Subnet = "192.168.xyz."
1..254|ForEach-Object{
    Start-Process -WindowStyle Hidden ping.exe -Argumentlist "-n 1 -l 0 -f -i 2 -w 1 -4 $SubNet$_"
}
$Computers =(arp.exe -a | Select-String "$SubNet.*dynam") -replace ' +',','|
  ConvertFrom-Csv -Header Computername,IPv4,MAC,x,Vendor|
                   Select Computername,IPv4,MAC

ForEach ($Computer in $Computers){
  nslookup $Computer.IPv4|Select-String -Pattern "^Name:\s+([^\.]+).*$"|
    ForEach-Object{
      $Computer.Computername = $_.Matches.Groups[1].Value
    }
}
$Computers
$Computers | Export-Csv $FileOut -NotypeInformation
#$Computers | Out-Gridview

Sample Output

Computername     IPv4            MAC              
------------     ----            ---              
Zyxel-24G-Switch 192.168.xyz.1   fc-f5-28-fc-f5-28
TMDat1-Plex      192.168.xyz.60  02-7c-2c-02-7c-2c
HPn54L           192.168.xyz.91  c8-cb-b8-c8-cb-b8
Medion-Tablett   192.168.xyz.114 08-d8-33-08-d8-33
dLAN-LiveCam     192.168.xyz.115 bc-f2-af-bc-f2-af
McMini           192.168.xyz.128 40-6c-8f-40-6c-8f
HPojPro8500plus  192.168.xyz.144 d4-85-64-d4-85-64
Amazon-Kindle2   192.168.xyz.152 10-ae-60-10-ae-60
SG-S4-active     192.168.xyz.162 40-0e-85-40-0e-85
TMDat1           192.168.xyz.167 28-92-4a-28-92-4a
HP-G1610         192.168.xyz.176 10-60-4b-10-60-4b
NetStream4Sat    192.168.xyz.191 00-0c-6c-00-0c-6c
Netio230b        192.168.xyz.230 24-a4-2c-24-a4-2c
fritz            192.168.xyz.250 bc-05-43-bc-05-43
HomeMatic-CCU    192.168.xyz.254 00-1a-22-00-1a-22

My own extended version appends the Vendor extracted from the first 6 hex digit of the Mac but requires the very slow download of Oui.txt from
"http://standards-oui.ieee.org/oui.txt"

1
  • How can I filter using mac address. I just want to save only IP in txt file. My MAC starts with "00:1f" Mar 8 at 11:05
2

I use NETSTAT all the time to figure out what applications are doing.

From a normal cmd prompt:

netstat -b

will return all connections and the app associated with it.

Here's a sample of what netstat returns:

 TCP    127.0.0.1:50452        iqbrix-pc:15485        ESTABLISHED
 [Everything.exe]
  TCP    192.168.4.210:27036    ZOE-SURFACE:55915      ESTABLISHED
 [Steam.exe]
  TCP    192.168.4.210:49674    server18101:5938       ESTABLISHED
 [TeamViewer_Service.exe]
  TCP    192.168.4.210:49798    msnbot-65-52-108-183:https  ESTABLISHED
  WpnService
 [svchost.exe]
  TCP    192.168.4.210:49829    pf-in-f109:imaps       ESTABLISHED
  OneSyncSvc_320294
 [svchost.exe]

You could parse the data that is returned and move from there.

3
  • Windows 10: The requested operation requires elevation.
    – Amit Naidu
    Feb 25 at 21:45
  • @AmitNaidu go to Start, type "cmd" when the "command prompt" app appears, right-click - "run as admin" Jul 14 at 5:50
  • Yes, I meant to document that this command requires elevation now, so it is not useful for regular users, like those of us on corporate workstations. You can still run netstat without the -b option though.
    – Amit Naidu
    Jul 14 at 20:10
2

Can find dns with "Resolve-DnsName", and mac/ips with "Get-NetNeighbor" (arp table cache). Can scan ips and use "Test-Connection" (ping). "Test-Connection" also lets you look for open tcp ports, so if port 80 is open you can go to that address in the browser, or if port 135 is open can go to that fileshare address. Finally, if you still can't identify the devices you can use a site to lookup the mac address given with arp or use the code at the bottom.

Using the arp table cache to find devices

requires powershell 7 or higher:

#replace the string with e.g. "192.168.1.$_", whatever your subnet is, optional but will improve # of devices found
$ips= 0..255 | %{"10.0.0.$_"};

#optional: add ports to scan. 22=ssh, 80=http, 443=https, 135=smb, 3389=rdp
$ports= 22, 80, 443, 135, 3389;

#optional: change batch size to speed up / slow down (warning: too high will throw errors)
$batchSize=64;

$ips += Get-NetNeighbor | %{$_.IPAddress}
$ips = $ips | sort | unique;
$ips | % -Throttlelimit $batchSize -Parallel {
    $ip=$_;
    $activePorts = $using:ports | %{ if(Test-Connection $ip -quiet -TcpPort $_ -TimeoutSeconds 1){ $_ } }
    if(Test-Connection $ip -quiet -TimeoutSeconds 1 -count 1){
        [array]$activePorts+="(ping)";
    } 
    if($activePorts){
        $dns=(Resolve-DnsName $ip -ErrorAction SilentlyContinue).NameHost;
        $mac=((Get-NetNeighbor |?{$_.State -ne "Incomplete" -and $_.State -ne "Unreachable" -and $_.IPAddress -match $ip}|%{$_}).LinkLayerAddress )
        return [pscustomobject]@{dns=$dns; ip=$ip; ports=$activePorts; mac=$mac}
    }
} | tee -variable "dvcResults"
$dvcResults | sort -property mac

note: You can't be sure about dns because a reverse zone may not be configured. (so the dns field may not be perfect)

If you want to lookup the mac address you can use the code below to append this data or go to a website (note: the code below downloads data from standards-oui.ieee.org/oui/oui.txt )

#build dict
$oui = (irm standards-oui.ieee.org/oui/oui.txt) -split '\r?\n';
$dict=@{};
$oui | ?{$_ -match "^[^\s]{8}"} | %{$arr=$_ -split "\s+";$dict[$arr[0]]=(($arr |select-object -skip 2) -join " ")}

#append data
$dvcDescriptions = $dvcResults | %{[pscustomobject]@{dns=$_.dns; ip=$_.ip; ports=$_.ports; companyName=$_.mac ? $dict[$_.mac.Substring(0,8)] : ""; mac=$_.mac;}};

$dvcDescriptions | sort -property companyName | Format-Table

Ex. output:

ex output

Output shows an asus computer hosting a windows fileshare, a dell server hosting https, a raspberry pi with ssh, a mac mini, and an hp printer hosting a webserver. If I go into my router page I can see the raspberry pi device name (pizero1) which our resolve-dnsname wasn't able to figure out.

1
  • 1
    Upvoting , finds enough machines to include the raspi and what i guess are Bonjour broadcasts. The accepted answer by user6811411 gave no useable results at all on my network.
    – user337598
    Nov 23, 2021 at 20:41
0

Get-NetIPAddress will display the IP addresses, both IPv4 and IPv6. You might've confused IPv6 addresses for MAC.

1
  • If I wanted to do this on my home network, I would have to get the info from my router. My PC doesn't know about some of the devices in the network. Jan 22, 2017 at 0:21
0

ForEach-Object : Parameter set cannot be resolved using the specified named parameters. At C:\scripts\Wrapper.ps1:12 char:8

  • $ips | % -Throttlelimit $batchSize -Parallel {
  •    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : MetadataError: (:) [ForEach-Object], ParameterBindingException
    • FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.ForEachObjectCommand

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.