1

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.

Mark Deven
  • 1,488
  • 9
  • 40
  • 71
  • You could `ping ` to get the IP. – confetti Aug 16 '18 at 22:14
  • That gives the MAC address – Mark Deven Aug 17 '18 at 00:01
  • 1
    Mark - I'd like to see the `ping ` 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 -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. – Vomit IT - Chunky Mess Style Aug 17 '18 at 03:09
  • another duplicate: [How to find the IP of a server address using cmd](https://superuser.com/q/303550/241386) – phuclv Aug 17 '18 at 06:37
  • Indeed a dupe, missed those sorry – Mark Deven Aug 17 '18 at 11:31

2 Answers2

6

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
OOOO
  • 1,232
  • 5
  • 12
S.Leon
  • 470
  • 2
  • 5
1

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

Next-Door Tech
  • 1,252
  • 8
  • 22