I’m looking for a command line tool which gets an IP address and returns the host name, for Windows.
asked Oct 13, 2009 at 14:27
1
The command you are looking for is called nslookup
, works fine for reverse lookups IFF someone has configured a reverse zone file, which they don’t always do.
answered Oct 13, 2009 at 14:29
0
if all the above fails, and you are specifically looking for a Windows machine, you can use
nbtstat -a 192.168.1.50
The data returned will be all the NetBIOS records the machine has. The one with a <20h> record type will usually be the machine’s name.
answered Oct 13, 2009 at 16:32
MooseMoose
1,6411 gold badge9 silver badges7 bronze badges
7
For many IP addresses you could just use ping -a, for example
ping -a 209.85.229.106
will return
Pinging ww-in-f106.google.com [209.85.229.106] with 32 bytes of data:
Reply from 209.85.229.106...........
answered Oct 13, 2009 at 14:44
Marko CarterMarko Carter
4,0921 gold badge30 silver badges38 bronze badges
4
If you use nslookup command with the IP address as its first argument will return the PTR record (the reverse entry) if it exists. For example:
nslookup 192.168.1.50
answered Oct 13, 2009 at 14:36
Kyle BrandtKyle Brandt
83.7k74 gold badges307 silver badges448 bronze badges
(tested under Windows 10 x64)
From command line:
FOR /F "tokens=2 delims= " %A in ('2^>NUL NSLOOKUP "%IP_ADDRESS%" ^| FINDSTR /C:": "') do ECHO %A
Within a script:
FOR /F "tokens=2 delims= " %%A in ('2^>NUL NSLOOKUP "%IP_ADDRESS%" ^| FINDSTR /C:": "') do ECHO %%A
Two (side)notes:
- To supress
NSLOOKUP
errors you have to use2^>NUL
instead of1^>NUL
- I’ve used
FINDSTR /C
to extract the value after the four whitespace characters. As the four spaces only seem to exist for theName:
entry, this appears to be only way to make it work on other localized systems.
JimNim
2,78613 silver badges24 bronze badges
answered Jul 17, 2017 at 14:22
script’n’codescript’n’code
1611 gold badge1 silver badge7 bronze badges
Use dig. A Windows port is available from the ISC here (look in the immediate download box for the link to the zip file). Here’s their man page reference for dig.
Ward’s point about the reverse lookup records often not getting created is very much true. Reverse lookups often do fail because many admins don’t bother creating the ptr records.
answered Oct 13, 2009 at 14:35
squillmansquillman
37.9k12 gold badges92 silver badges146 bronze badges
tracert
might be an option.
tracert 10.12.190.51
Results in:
Tracing route to LAP8662.aus.int.example.com [10.12.190.51]
over a maximum of 30 hops:
1 <1 ms <1 ms <1 ms LAP8662.aus.int.example.com [10.12.190.51]
Trace complete.
answered Dec 7, 2022 at 5:14
FidelFidel
3731 gold badge4 silver badges19 bronze badges
4
if you want to know the host-name in same network then please use another machine which have same network and use below commend
Ping -an ip addres
answered Jun 27, 2017 at 23:34
1
psexec \192.168.0.65 hostname
DMHD006
hostname exited on 192.168.0.65 with error code 0.
answered Jul 25, 2019 at 8:29
1
You must log in to answer this question.
Not the answer you’re looking for? Browse other questions tagged
.
Not the answer you’re looking for? Browse other questions tagged
.
I’m looking for a command line tool which gets an IP address and returns the host name, for Windows.
asked Oct 13, 2009 at 14:27
1
The command you are looking for is called nslookup
, works fine for reverse lookups IFF someone has configured a reverse zone file, which they don’t always do.
answered Oct 13, 2009 at 14:29
0
if all the above fails, and you are specifically looking for a Windows machine, you can use
nbtstat -a 192.168.1.50
The data returned will be all the NetBIOS records the machine has. The one with a <20h> record type will usually be the machine’s name.
answered Oct 13, 2009 at 16:32
MooseMoose
1,6411 gold badge9 silver badges7 bronze badges
7
For many IP addresses you could just use ping -a, for example
ping -a 209.85.229.106
will return
Pinging ww-in-f106.google.com [209.85.229.106] with 32 bytes of data:
Reply from 209.85.229.106...........
answered Oct 13, 2009 at 14:44
Marko CarterMarko Carter
4,0921 gold badge30 silver badges38 bronze badges
4
If you use nslookup command with the IP address as its first argument will return the PTR record (the reverse entry) if it exists. For example:
nslookup 192.168.1.50
answered Oct 13, 2009 at 14:36
Kyle BrandtKyle Brandt
83.7k74 gold badges307 silver badges448 bronze badges
(tested under Windows 10 x64)
From command line:
FOR /F "tokens=2 delims= " %A in ('2^>NUL NSLOOKUP "%IP_ADDRESS%" ^| FINDSTR /C:": "') do ECHO %A
Within a script:
FOR /F "tokens=2 delims= " %%A in ('2^>NUL NSLOOKUP "%IP_ADDRESS%" ^| FINDSTR /C:": "') do ECHO %%A
Two (side)notes:
- To supress
NSLOOKUP
errors you have to use2^>NUL
instead of1^>NUL
- I’ve used
FINDSTR /C
to extract the value after the four whitespace characters. As the four spaces only seem to exist for theName:
entry, this appears to be only way to make it work on other localized systems.
JimNim
2,78613 silver badges24 bronze badges
answered Jul 17, 2017 at 14:22
script’n’codescript’n’code
1611 gold badge1 silver badge7 bronze badges
Use dig. A Windows port is available from the ISC here (look in the immediate download box for the link to the zip file). Here’s their man page reference for dig.
Ward’s point about the reverse lookup records often not getting created is very much true. Reverse lookups often do fail because many admins don’t bother creating the ptr records.
answered Oct 13, 2009 at 14:35
squillmansquillman
37.9k12 gold badges92 silver badges146 bronze badges
tracert
might be an option.
tracert 10.12.190.51
Results in:
Tracing route to LAP8662.aus.int.example.com [10.12.190.51]
over a maximum of 30 hops:
1 <1 ms <1 ms <1 ms LAP8662.aus.int.example.com [10.12.190.51]
Trace complete.
answered Dec 7, 2022 at 5:14
FidelFidel
3731 gold badge4 silver badges19 bronze badges
4
if you want to know the host-name in same network then please use another machine which have same network and use below commend
Ping -an ip addres
answered Jun 27, 2017 at 23:34
1
psexec \192.168.0.65 hostname
DMHD006
hostname exited on 192.168.0.65 with error code 0.
answered Jul 25, 2019 at 8:29
1
You must log in to answer this question.
Not the answer you’re looking for? Browse other questions tagged
.
Not the answer you’re looking for? Browse other questions tagged
.
This article explains how to find out the hostname of a computer connected to a local network using the IP address. Depending on the type of IP address — public or private — there are two different procedures. Here we will give an easy hint on how to do this.
How to find a hostname via public IP address?
In order to find the hostname of a computer with a public IP address, you have to pass the address to the Domain Name System (DNS) server. Here are the steps to follow:
- Click on the Window Start button.
- Click on “All Programs”.
- Click on “Accessories”.
- Right-click on «Command Prompt«.
- Choose «Run as Administrator«.
- Type “nbtstat -a <ip_address>”. Note that <ip_address> is the IP address of the computer.
How to find a hostname via private IP address?
Finding the hostname of a computer with a private IP address and no local DNS server means you need to query the host itself by using a Windows utility. Here are the steps to follow:
- Click on the Window Start button.
- Click on “All Programs”.
- Click on “Accessories”.
- A black box opens.
- Type «nslookup -a <ip_address>«. Note that <ip_address> is the IP address of the computer.
Note that it is not necessary to know an IP address in order to find other systems if you have a WiFi LAN connection.
We hope that you find these solutions useful and that your question is answered!
Do you need more help with finding an IP address? Check out our forum!
Using Resolve-DnsName
Cmdlet
To retrieve the hostname from the given IP address in PowerShell, use the Resolve-DnsName
cmdlet with -Type
and PTR
parameters.
Resolve—DnsName —Type PTR —Name 8.8.8.8 | Select—Object —ExpandProperty NameHost |
In this example, the Resolve-DnsName
cmdlet resolves the IP addresses to DNS names (hostnames). The -Type
parameter is used to specify that the query should be for a PTR record (a PTR
record is a type of Domain Name System record that maps an IP address to a hostname), and the -Name
parameter specified the IP address we want to resolve.
The command then pipes the output to the Select-Object
cmdlet to expand the NameHost
property, which contains the hostname corresponding to the IP address. The output is then piped to the Select-Object
cmdlet to expand the NameHost
property, which contains the hostname corresponding to the IP address.
Replace the
8.8.8.8
with the IP address you want to resolve.
Using nslookup
Command
Use the nslookup
to get hostname from IP address in PowerShell.
$ipAddress = «213.133.127.245» nslookup $ipAddress | Select—String —Pattern ‘Name:’ |
Name: kronos.alteregomedia.org |
This code used the nslookup
command to request the DNS server for the hostname associated with the IP address 213.133.127.245
. The nslookup
command output is piped to the Select-String
cmdlet, which searches for lines containing the Name:
, which includes the hostname information.
Using [System.Net.Dns]::GetHostByAddress
Method
Use the [System.Net.Dns]::GetHostByAddress
method to get hostname from IP address in PowerShell.
$ipAddress = «8.8.8.8» $hostEntry = [System.Net.Dns]::GetHostByAddress($ipAddress) $hostname = $hostEntry.HostName Write—Host «The hostname associated with IP address $ipAddress is $hostname» |
The hostname associated with IP address 8.8.8.8 is dns.google |
We can observe the above code retrieved the hostname of a given IP address. In this example, the $ipAddress
variable contained the IP address we wanted to resolve. The [System.Net.Dns]::GetHostByAddress
method used this $ipAddress
variable as an input and returned the System.Net.IPHostEntry
object that contains various details about the host. Once this object is returned, the .HostName
property of the IPHostEntry
object extracts the hostname.
That’s all about how to get hostname from IP address in PowerShell.
How to get HostName by IP in Windows?
To get HostName from IP in Windows, you can use one of the below options:
Ping
Command-Line.nbtstat
Command-Line.nslookup
Command-Line.Reverse DNS Lookup
online tool
1) Get Hostname from IP using Ping
You can use the Ping command-line to get hostname by IP as the following:
- Open CMD.
-
Run the below command-line
ping -a ServerIP
- The result should look like
Ping is the primary TCP/IP command used to troubleshoot connectivity, reachability, and name resolution. it is available only if you have installed the TCP/IP protocol.
2) Get Hostname with IP using nbtstat
You can use the nbtstat command-line to get hostname with IP as the following:
- Open CMD.
-
Run the below command-line
nbtstat -a ServerIP
- The result should look like
nbtstat displays NetBIOS over TCP/IP (NetBT) protocol statistics, NetBIOS name tables for both the local computer and remote computers, and the NetBIOS name cache, it is available only if you have installed the TCP/IP protocol.
3) Get Hostname by IP using nslookup
You can use the nslookup command-line to get hostname from IP as the following:
- Open CMD.
-
Run the below command-line
nslookup ServerIP
- The result should look like
The nslookup displays information that you can use to diagnose Domain Name System (DNS) infrastructure. it is available only if you have installed the TCP/IP protocol.
4) How to get HostName of IP Online?
You can also get the Hostname of IP Online using a Reverse DNS Lookup online tool as the following:
- Open Reverse DNS Lookup online tool
- Type your IP Address that you would like to get its corresponding HostName.
- Click
Lookup Hostname
to show the result
Applies To
- Windows 10
- Windows Server