3

I would like to be able to ping whatever machine name I am in without first having to do:

localhost

Can I do something like the following?

ping %localhost%

When I do:

ping localhost

the IP number is 127.0.0.1 which is not what I want. I want the IP number assigned by my router.

CJ7
  • 1,149

4 Answers4

7

You could use %COMPUTERNAME% on Windows.

But it really should not matter, since the packets will never be sent over the network. When you ping the computer's own address – any address, whether loopback or not – Windows recognizes this and loops back the packets inside the OS. It would simply be impractical for it to do otherwise.

On Windows, you can confirm this by reading the route table from route print – pay attention to the "Gateway" column:

C:\>ipconfig | findstr "Address"
        IP Address. . . . . . . . . . . . : 192.168.1.223
        IP Address. . . . . . . . . . . . : fe80::202:2dff:fe6b:c71c%6

C:\>route print | findstr "Netmask 127.0.0.1"
Network Destination        Netmask          Gateway       Interface  Metric
        127.0.0.0        255.0.0.0        127.0.0.1       127.0.0.1       1
    192.168.1.223  255.255.255.255        127.0.0.1       127.0.0.1       30
grawity
  • 501,077
1

Use ipconfig to find the IP address assigned to you by your router:

Windows IP Configuration

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . : <domain>.local
Link-local IPv6 Address . . . . . : <IPv6 address>
IPv4 Address. . . . . . . . . . . : <IPv4 address>
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : <IP Address>

Use ping -a localhost to find the machine name.

-a Resolve addresses to hostnames.

ChrisF
  • 41,540
1

ping localhost

the IP number is 127.0.0.1 which is not what I want. I want the IP number assigned by my router.

localhost is defined to be 127.0.0.1.

If you want to ping yourself over the Internet, visit a website like http://www.whatismyip.com/ and type ping ip-address where ip-address is the address you read from the website.

SecurityMatt
  • 3,200
0

To do this in a single command run nbtstat -n

nbtstat is a windows NetBIOS tool. I used to use it to get the computername of other computers from their IP using netbios -A <IPAddress>

Jesse
  • 46
  • 1