get current ip and hostname using ping -4 -a ""

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

get current ip and hostname using ping -4 -a ""

#1 Post by carlos » 21 Nov 2014 12:53

Hello. I found some curious thing.
When you use ping -a and specify empty string: ""

It use the hostname of your computer.

Using this:

Code: Select all

ping -4 -a ""
you get your computer name and your ip.:

Code: Select all

C:\Users\areaweb2>ping -4 -a ""

Haciendo ping a PC01 [192.168.10.201] con 32 bytes de datos:
Respuesta desde 192.168.10.201: bytes=32 tiempo<1m TTL=128

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

Re: get current ip and hostname using ping -4 -a ""

#2 Post by Compo » 21 Nov 2014 13:06

Same here in Windows Technical Preview [Version 6.4.9879]

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: get current ip and hostname using ping -4 -a ""

#3 Post by Squashman » 21 Nov 2014 14:44

This works as well.
ping ""

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: get current ip and hostname using ping -4 -a ""

#4 Post by foxidrive » 21 Nov 2014 17:19

ping -4 "" works as carlos says and gives me an IPV4 address and
ping "" works too but gives me an IPV6 address

It works in XP Pro (no IPV6 there) and Windows 8.1

That's really cool - a neat shortcut!


Edit: I should make it clear that I get the computer name and IP address without the -a switch.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: get current ip and hostname using ping -4 -a ""

#5 Post by Squashman » 21 Nov 2014 20:32

Windows 7 gives me IP4 with just the quotes. It also gives host name.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: get current ip and hostname using ping -4 -a ""

#6 Post by foxidrive » 21 Nov 2014 21:37

Squashman wrote:Windows 7 gives me IP4 with just the quotes. It also gives host name.


Yes, it depends on the modem being used for the internet connection UIAM.

When I got an IPV6 capable modem then Windows started showing me IPV6 addesses, even though IPV6 was disabled in the modem by default.

bars143
Posts: 87
Joined: 01 Sep 2013 20:47

Re: get current ip and hostname using ping -4 -a ""

#7 Post by bars143 » 21 Nov 2014 23:02

it does not need findstr to extract ip adress of hostname.

Post Reply