Skip to Content

How Can I Find a Hostname from an IP Address on Windows?

What’s the Easiest Way to Resolve a Hostname Using an IP in Windows?

Have you ever had an IP address and wondered which computer or server it belongs to? You might need to find the “hostname,” which is the human-readable name for a device on a network, like “Johns-PC” or “Main-Server.” This is a common task for IT professionals, network administrators, or anyone curious about their network. You want a simple way to do this using the command line on a Windows computer.

Solutions in Detail

Finding a hostname from an IP address is often called a “reverse DNS lookup.” Your computer asks the network’s phonebook (DNS server), “Who is at this address?” If the records are set up correctly, the server replies with the name. Below are several command-line tools and methods you can use on Windows to get this information. Each has its strengths, and some may work when others don’t.

Using nslookup

The nslookup command, which stands for “name server lookup,” is the primary tool for this job. It’s designed to talk to DNS servers to get information. To find a hostname, you simply give it the IP address.

How to Use It: Open your Command Prompt and type nslookup followed by the IP address you want to check.

nslookup 209.85.229.106

What Happens: The tool will contact the default DNS server and ask for the name associated with that IP address. If it finds a name, the output will show it. However, this only works if the network administrator has created a “reverse zone file” or “PTR record.” Think of it as an address book that works backward—from address to name. Many admins don’t set this up, so nslookup might fail even if the device has a name.

Example Output:

Name: ww-in-f106.google.com
Address: 209.85.229.106

Pinging with the -a Switch

The ping command is famous for testing if another computer is reachable. But it has a helpful option, -a, that tells it to also find the hostname of the IP address you are pinging. This is one of the simplest methods to try.

How to Use It: In the Command Prompt, type ping -a and then the IP address.

ping -a 209.85.229.106

What Happens: Your computer will send small data packets to the target IP address and, at the same time, perform a reverse DNS lookup. The result will show the hostname in the very first line of the output before it starts showing the reply times. Like nslookup, this relies on a correctly configured PTR record, so it may not always work.

Example Output:

Pinging ww-in-f106.google.com [209.85.229.106] with 32 bytes of data:
Reply from 209.85.229.106: bytes=32 time=10ms TTL=118

Checking NetBIOS with nbtstat

If you are on a local network (like in an office or at home) and the other methods fail, nbtstat can be very effective. This command looks for NetBIOS names, which is an older naming system Windows computers use to identify themselves on a local network. It works even without a DNS server.

How to Use It: Use the -a flag (which means “adapter status”) followed by the IP address of the local machine.

nbtstat -a 192.168.1.50

What Happens: The command queries the device directly for its list of registered NetBIOS names. The output will be a table of names and their types. The computer’s primary name usually has a <20> or <20h> record type listed next to it under the “Type” column. This method is great for finding the names of other Windows machines on your LAN but won’t work for devices on the internet.

Example Output:

NetBIOS Remote Machine Name Table

Name Type Status
---------------------------------------------
WORKSTATION-01 <00> UNIQUE Registered
WORKGROUP <00> GROUP Registered
WORKSTATION-01 <20> UNIQUE Registered

In this example, WORKSTATION-01 is the hostname.

Using tracert to Find the Name

The tracert (Trace Route) command is designed to show you the path your data takes to reach a destination. A useful side effect is that it tries to resolve the name of each “hop” along the way, including the final destination.

How to Use It: Type tracert followed by the IP address.

tracert 10.12.190.51

What Happens: The command will begin tracing the network route. The very first line of the output often shows the hostname of the target IP address before it lists the individual hops. If the device is on your local network, the trace might complete in a single hop, giving you the name right away.

Example Output:

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.

Advanced Scripting with FOR and nslookup

For those who need to automate this process in a batch script, you can combine nslookup with a FOR loop to extract just the hostname and nothing else. This is a more technical approach but gives you a clean output.

How to Use It: This command is a bit more complex. It runs nslookup, finds the line with the hostname, and then pulls out only the name.

In a script, you would first set the IP address variable and then run the loop:

@ECHO OFF
SET IP_ADDRESS=192.168.1.50
FOR /F "tokens=2 delims= " %%A in ('2^>NUL NSLOOKUP "%IP_ADDRESS%" ^| FINDSTR /C:": "') do ECHO %%A

What Happens: The FOR command processes the output of nslookup. The FINDSTR part filters the output to only the line containing “Name: “, and tokens=2 grabs the second piece of that line, which is the hostname itself. The 2^>NUL part is there to hide any error messages from nslookup if it fails, keeping your script’s output clean.

Using an External Tool: dig

While not built into Windows, dig (Domain Information Groper) is a powerful and flexible command-line tool used by many network professionals. You can download a Windows version from the ISC (Internet Systems Consortium), the organization that maintains it. dig gives you more detailed information than nslookup.

How to Use It: Once installed, you can perform a reverse lookup using the -x flag.

dig -x 209.85.229.106

What Happens: dig will perform a reverse lookup and give you a detailed response, including the “ANSWER SECTION,” where you will find the PTR record showing the hostname. Many professionals prefer dig because its output is clearer and more predictable than nslookup’s.

Remote Execution with psexec

If you have administrative rights on the remote computer, you can use psexec, a tool from Microsoft’s Sysinternals suite, to run the hostname command directly on that machine. This method doesn’t rely on DNS at all; it queries the machine’s operating system directly.

How to Use It: You’ll need to download psexec first. Then, run the following command, replacing the IP with your target.

psexec \\192.168.0.65 hostname

What Happens: psexec connects to the remote computer over the network and executes the hostname command there. The remote computer then reports its own name back to your command prompt. This is a very reliable method for machines on a corporate network where you have the necessary permissions.