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.

  • You could ping <hostname> to get the IP.
    – confetti
    Aug 16 '18 at 22:14
  • That gives the MAC address
    – Mark Deven
    Aug 17 '18 at 0:01
  • 1
    Mark - I'd like to see the ping <hostname> with a batch script return the MAC address—that doesn't sound right to me. For example from command line you can run for /f "delims=[] tokens=2" %a in ('ping <hostname> -n 1') do echo %a to get an IP address from Windows 10 for example. What type of special configuration are you working with or help clarify on that statement a bit otherwise about getting the MAC address. Aug 17 '18 at 3:09
  • another duplicate: How to find the IP of a server address using cmd
    – phuclv
    Aug 17 '18 at 6:37
  • Indeed a dupe, missed those sorry
    – Mark Deven
    Aug 17 '18 at 11:31

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.


@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...


According to this web page (1), you can use the nslookup (2) command to print out some information about a computer including its IP based on its hostname address. You could then filter out only the IP using findstr (3).


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