Networking – How to get the ip address of a computer from its hostname?

batchhostnameiplannetworking

I have the name of a computer on the network, and I need to know how to get the ip address of said computer from a batch file? Thanks.

Best Answer

Your problem can be solved via command. Like the picture I posted below. You may have mistakenly marked the yellow mark as a MAC address, but they are actually IPv6 addresses. When you use the ping command, you can add "-4" behind the host name to display the IPv4 address.

ping hostname -4

enter image description here

I also have a batch file that returns the hostname and IP address of the computer at the same time. You can write the following code to a txt file and change the extension to .bat. Then double-click the file to get the computer name and ip address. I hope this will help you.

Code:

@echo off

 title Display your IP and hostname

 color F9

 @echo -

 for /f "tokens=2 delims=:" %%i in ('ipconfig^|findstr "Address"') do set ip=%%i

 @echo Your ip address is :%ip%

 @echo Your computer name is :%COMPUTERNAME%

Echo press any key to exit...

pause>NUL
Related Question