Completely confused by PING 192.168.0.2
Posted: 28 Feb 2018 05:31
Apologies if this doesn't strictly fit this forum. I'll take no offense if you incinerate it, but tell me where to go if you do. It does involve strictly DOS operation and .BAT in particular.
Right up front, I am ignorant about IP addressing, and what PING and NET USE truly do. I have a basic functional understanding, and know many fragmented details about it, so I won't be as bad as explaining this to your grandmother, but just be warned that I am essentially a connectivity novice.
Scenario: I have two desktops each connected to a cable modem/router. On an XP box I go
net use \\192.168.0.2\users /user:bob
SUBST Q: "\\192.168.0.2\users\bob"
and now I can use Q: from the other (Win 7) box. I commonly run a batch file, and when the other box is turned on and "advanced sharing" c:\users\ there, I want to have the XP batch file go
Q:
cd \foo
However, when the 2nd box is off or asleep or whatever, that Q: can sit there for an eternity before giving up. My solution was to go
ping 192.168.0.2 -n 1 -w 200
and I test the text it returns (because I got misleading, seemingly absurd values from ERRORLEVEL). So I go
for /f %%i in ('ping 192.168.0.2 -n 1 -w 200 ^| findstr /C:"Received = 1"') do (
set state=up
)
if %state% == down (etc.)
Don't worry about the complex "FOR" command. All it's doing is setting an environment variable if "Received = 1" is returned by the ping.
Here's where it gets deeply frustrating. Sometimes I CAN ping it, but I know that the device on the other end is not sharing. That is, dir Q: says "the network name cannot be found" - yet the PING SUCCEEDS.
Today, something new: the ping is failing 100% of the time, even though I can go
DIR Q:
and see everything on the other end of the connection.
BTW I don't know what it means, but you might be interested to hear that ARP -a shows
Interface: 192.168.0.3 --- 0x2
Internet Address Physical Address Type
192.168.0.1 xx-xx-xx-xx-xx-xx dynamic
192.168.0.2 yy-yy-yy-yy-yy-yy dynamic
The goal here is to, in a .BAT, to test if Q is accessible, before issuing
Q:
cd \foo
because it can sit there for a head-splitting eternity if Q: is not currently accessible.
FWIW, I spent hours googling and testing false leads. I found surprisingly few answers on how to test if a drive is currently shared, and the little advice I found is often bad. PING seemed to be my best hope, but I'm open to something else.
Right up front, I am ignorant about IP addressing, and what PING and NET USE truly do. I have a basic functional understanding, and know many fragmented details about it, so I won't be as bad as explaining this to your grandmother, but just be warned that I am essentially a connectivity novice.
Scenario: I have two desktops each connected to a cable modem/router. On an XP box I go
net use \\192.168.0.2\users /user:bob
SUBST Q: "\\192.168.0.2\users\bob"
and now I can use Q: from the other (Win 7) box. I commonly run a batch file, and when the other box is turned on and "advanced sharing" c:\users\ there, I want to have the XP batch file go
Q:
cd \foo
However, when the 2nd box is off or asleep or whatever, that Q: can sit there for an eternity before giving up. My solution was to go
ping 192.168.0.2 -n 1 -w 200
and I test the text it returns (because I got misleading, seemingly absurd values from ERRORLEVEL). So I go
for /f %%i in ('ping 192.168.0.2 -n 1 -w 200 ^| findstr /C:"Received = 1"') do (
set state=up
)
if %state% == down (etc.)
Don't worry about the complex "FOR" command. All it's doing is setting an environment variable if "Received = 1" is returned by the ping.
Here's where it gets deeply frustrating. Sometimes I CAN ping it, but I know that the device on the other end is not sharing. That is, dir Q: says "the network name cannot be found" - yet the PING SUCCEEDS.
Today, something new: the ping is failing 100% of the time, even though I can go
DIR Q:
and see everything on the other end of the connection.
BTW I don't know what it means, but you might be interested to hear that ARP -a shows
Interface: 192.168.0.3 --- 0x2
Internet Address Physical Address Type
192.168.0.1 xx-xx-xx-xx-xx-xx dynamic
192.168.0.2 yy-yy-yy-yy-yy-yy dynamic
The goal here is to, in a .BAT, to test if Q is accessible, before issuing
Q:
cd \foo
because it can sit there for a head-splitting eternity if Q: is not currently accessible.
FWIW, I spent hours googling and testing false leads. I found surprisingly few answers on how to test if a drive is currently shared, and the little advice I found is often bad. PING seemed to be my best hope, but I'm open to something else.