Microcyb
(Getting the hang of it)
2003-02-28 04:40 PM
The correct format.

O.K. I tend to hate this, but here is goes.
Does anyone know the correct format of the following command to use in Win9x, and not NT/2k

c:\winnt\system32\cmd.exe /Q /E:1024 /C FOR /F "TOKENS=2* DELIMS= " %%i IN ('"PING -a -n 1 216.239.51.100 | FIND "]""') DO ECHO %%i >c:\report.txt
pause

This will work in a NT format, but get an invalid switch for Win9x.

Sad thing is that I cannot find out where that invalid witch is.

Any Clues????


Les
(KiX Master)
2003-02-28 04:45 PM
Re: The correct format.

well the first clue is that "c:\winnt\system32\cmd.exe" is NT specific. Should be %comspec%.

But then you probably are not using "c:\winnt\system32\cmd.exe" or else you would not be getting an "invalid switch" error.

I don't have any Wintendos to test on but my guess it the /Q switch. Spark up a DOS box and enter COMMAND /? to see the valid switches.


Microcyb
(Getting the hang of it)
2003-02-28 04:53 PM
Re: The correct format.

LOL yes I know that c:\windows\command.com, and c:\winnt]system32\cmd.exe are the two different ones.
Thanks for pointing that out LLigetfa.

I do have %comspec% in the Kix script, and then pulling the result, to display the information.

Al that works, but here is the main issues I have.

SHELL '%Comspec% /Q /E:1024 /C FOR /F "TOKENS=2* DELIMS= " %%i IN ('+ CHR(39)
+ '"PING -a -n 1 $ipnum | FIND "]""' + CHR(39) + ') DO ECHO %%i >' + $tempfile

Only works in a NT/2K/XP enviorment.

DOS only tells me I have an inavlid switch on a WIN9X platform.

And for the life of me I cannot find that stupid invalid switch. [Mad]

In short I was just trying to ping two IP's
One is google.com, and the other is behind a vpn.

Wanted to know the results of the two so that I can know if the user is logged onto the ISP, and then the VPN.

Using Watlz function this is what I have:
code:
 ? REVPING("1.1.100.229")
? @error
? REVPING("216.239.51.100")
? @error
? "DONE"
get $

FUNCTION REVPING($ipnum)
DIM $nameip, $tempfile
$tempfile = "%temp%\nameip.txt"

SHELL '%Comspec% /Q /E:1024 /C FOR /F "TOKENS=2* DELIMS= " %%i IN ('+ CHR(39)
+ '"PING -a -n 1 $ipnum | FIND "]""' + CHR(39) + ') DO ECHO %%i >' + $tempfile

IF OPEN(10,$tempfile,2) = 0 $nameip = READLINE(10)
ELSE $nameip = ""
ENDIF
IF CLOSE(10) = 0
DEL $tempfile
ENDIF
IF $nameip <> "" $revping = TRIM($nameip)
EXIT (0)
ELSE $revping = "UNRESOLVED"
EXIT (1)
ENDIF
ENDFUNCTION

It works just right, but only on a NT platform. [Embarrassed]

So Hopefully some OLD SCHOOL people can tell me what the hell is the invalid switch. [Big Grin]


JochenAdministrator
(KiX Supporter)
2003-02-28 04:54 PM
Re: The correct format.

forget it ...
I wrote it too (see ping() udf) and didn't found anything but that FOR isn't available in 9x [Roll Eyes]


JochenAdministrator
(KiX Supporter)
2003-02-28 04:56 PM
Re: The correct format.

Hmmm ... looking at the code tells me that I did actually wrote that line [Big Grin]

If you look a bit deeper you will find ping() udf which Waltz took and adapted to return names from ip ...

At least I mentioned in REQUIREMENTS the supported OS's [Wink]


Microcyb
(Getting the hang of it)
2003-02-28 05:05 PM
Re: The correct format.

Ahh O.K. jpols is de man to ask!
Your Ping() function also for a NT platform. it does in fact work perfect, and I do not reallt care about the DNS hostname conversion.

Here is the challenege for the day.
Can you, or is it possible to ping the followng IP's in a WIN9X platform:
VPN 1.1.100.229
PUBLIC 216.239.51.100
and just say true or false if it connected to the IP's or not?


JochenAdministrator
(KiX Supporter)
2003-02-28 05:06 PM
Re: The correct format.

Think you have to go the hard way piping the output to a textfile open, read and do a little string manipulation ... or you might also want to try one of the pipe() udfs we got

hth


JochenAdministrator
(KiX Supporter)
2003-02-28 05:09 PM
Re: The correct format.

Or did you meant saying if the ping returns reply ?

That is actually possible ... or was it a fact that 'find' also denied to work on 9x ?
Can't remember anymore ... long time not used 9x for anything else than gaming [Big Grin]


Microcyb
(Getting the hang of it)
2003-02-28 05:13 PM
Re: The correct format.

Ahhhh Gaming gooood.... [Smile]

But just want to do like this in DOS
ping 216.239.51.100

but in KIX how can you do that?

In short I just wanted to know if you pinged an ip it could tell you yeah I can see it, or NOPE cannot see that ip, so that the rest of my script will continue or not.

So if the script or a function could just outpu true or false the the IP in the request.


LonkeroAdministrator
(KiX Master Guru)
2003-02-28 05:15 PM
Re: The correct format.

my gaming platform is KiOSX, so need for win9x there either [Wink]

LonkeroAdministrator
(KiX Master Guru)
2003-02-28 05:25 PM
Re: The correct format.

sure it can [Wink]

something like:
code:
shell '%comspec% /c ping $ip | find "0% loss" >null'
if @error
"could not ping"
else
"ping succesfull"
endif



Microcyb
(Getting the hang of it)
2003-02-28 05:26 PM
Re: The correct format.

So any ideas guys?

Sealeopard
(KiX Master)
2003-02-28 05:49 PM
Re: The correct format.

So, what exactly is your problem? You cannot SHELL out your PING and then check a resulting text file?

Lonkeros code doesn't work for you?

The PING() UDF doesn't work for you?

Could you please be precise?

[ 28. February 2003, 17:50: Message edited by: sealeopard ]


JimRobinson
(Fresh Scripter)
2003-03-03 05:48 PM
Re: The correct format.

This may be a bit late, but FOR /F is not supported in 9x. I don't have any 9x boxes right at hand, so I can't be much more help than that on the shell side, but think you would probably be best off sending the output to file and parsing that in KiX.

JochenAdministrator
(KiX Supporter)
2003-03-03 08:15 PM
Re: The correct format.

Yep Jim,

think I mentioned that before [Razz] [Big Grin]

Hello Microcyb ???

You still around ?


Microcyb
(Getting the hang of it)
2003-03-17 07:01 PM
Re: The correct format.

Yep still around, and still no luck

LonkeroAdministrator
(KiX Master Guru)
2003-03-17 07:11 PM
Re: The correct format.

microcyb, what did my code return?

please, could you help us help you?


Microcyb
(Getting the hang of it)
2003-03-17 07:39 PM
Re: The correct format.

Well, not sure but every ping no matter if it is a bad ip or a good ip, says ping sucessfull.

so if I ran your script to ping 0.0.1.1 it says it pinged, and if you place in a good ip, it says the same result.


LonkeroAdministrator
(KiX Master Guru)
2003-03-17 07:43 PM
Re: The correct format.

well, simple check to ping reply retrieved that the string was little wrong.
you will be perfectly server with:
code:
$ip="0.0.1.1"
shell '%comspec% /c ping $ip | find "(0% loss)" >null'
if @error
"could not ping"
else
"ping succesfull"
endif



Microcyb
(Getting the hang of it)
2003-03-17 08:49 PM
Re: The correct format.

Still says ping succesfull even for a bad ip address.

LonkeroAdministrator
(KiX Master Guru)
2003-03-17 08:51 PM
Re: The correct format.

could you please tell what ping returns in win9x.

that code above works just fine on NT-based machines.


Les
(KiX Master)
2003-03-17 08:57 PM
Re: The correct format.

Works for me. Mind you, I don't have Wintendo to test on. Maybe should post back the code you are trying in case you are modifying Jooels.

[ 17. March 2003, 20:58: Message edited by: LLigetfa ]


JochenAdministrator
(KiX Supporter)
2003-03-17 09:58 PM
Re: The correct format.

Me, Awaiting Reply, Chief of Nutshell tribe says "TTL=" is only way white man gets right answer, Hugh !

LonkeroAdministrator
(KiX Master Guru)
2003-03-17 10:44 PM
Re: The correct format.

I was waiting for that comment jochen.
I don't like the ttl way and that's it.


Les
(KiX Master)
2003-03-17 11:13 PM
Re: The correct format.

Well there's already a gazillion examples posted using "TTL"...

NTDOCAdministrator
(KiX Master)
2003-03-17 11:47 PM
Re: The correct format.

Ugh... #$%@^

Can't believe author of PostPrep don't use for his own code posting either.

Very easy to setup a link/shortcut to run it Jooel [Eek!]

I'm getting lazy. Even short code is much easier to copy from board when PostPrep is used.

Now where did I hide that Write/MS Word application? [Razz]


ShaneEP
(MM club member)
2003-03-18 01:19 AM
Re: The correct format.

This works on XP and 98...

code:
 
$junkfile = "%temp%\winscl.xxx"
del $junkfile

shell '%comspec% /c ping -n 2 216.239.33.100 > $junkfile'
$filehandle = FreeFileHandle ( )
If Open ($filehandle, $junkfile) = 0
$line = ReadLine ($filehandle)
While @Error = 0
If InStr ($line, "Reply from")
$replies = 1
Endif
$line = ReadLine ($filehandle)
Loop
Endif
$null = Close ($filehandle)
del $junkfile

If $replies < 1
? "Server not responding at this time"
Else
? "The server is up"
Endif

get $



ShaneEP
(MM club member)
2003-03-18 01:28 AM
Re: The correct format.

Tried your snippet as well Lonkero. I also get ping successful on every address in win98, even though the "(0% loss)" should work...

code:
 
$ip="0.0.1.1"
shell '%comspec% /c ping $ip | find "(0% loss)" >null'
if @error
"could not ping"
else
"ping succesfull"
endif



[ 18. March 2003, 01:31: Message edited by: CitrixMan ]


LonkeroAdministrator
(KiX Master Guru)
2003-03-18 07:50 AM
Re: The correct format.

k, now we are helping a boy that seems not to wont that help.
shane, could you check on commandline what the find returns on win9x?
if it works as expected, do after it:
echo %errorlevel%

to see does win9x find return errorcode.
if it does, then command.com does not.


NTDOCAdministrator
(KiX Master)
2003-03-18 10:33 AM
Re: The correct format.

Lonkero,

Windows 95 does not have the 0% loss on my test system.

If you do this, it does find it, but apparently does not set an errorlevel when I echo %errorlevel% to the console it is blank.
If you give it something real to find it will display on console what it found, but if you give it something bogus to find it remains blank on console.



shell '%comspec% /c ping $ip | find "Request timed out" >null'



That's why you always get a SUCCESSFUL answer as the errorlevel is never set on Windows 95


LonkeroAdministrator
(KiX Master Guru)
2003-03-18 10:32 PM
Re: The correct format.

thanks for the answer.

ShaneEP
(MM club member)
2003-03-18 11:36 PM
Re: The correct format.

Yea...What NTDoc said... [Wink]

JochenAdministrator
(KiX Supporter)
2003-03-19 09:29 AM
Re: The correct format.

Ok,

if noone likes 'TLL=' I explain it more to the point and hopefully everyone will agree that it is the only way :

So, assuming you run Windows NT Workstation, how would you ever get a valid response in finding '0% loss' (there is never ever such a phrase on Console !)

sample :

quote:
C:\WINNT\system32>ping 10.128.12.20

Pinging 10.128.12.20 with 32 bytes of data:

Reply from 10.128.12.20: bytes=32 time=10ms TTL=125
Reply from 10.128.12.20: bytes=32 time<10ms TTL=125
Reply from 10.128.12.20: bytes=32 time<10ms TTL=125
Reply from 10.128.12.20: bytes=32 time<10ms TTL=125

C:\WINNT\system32>

(Have you noticed that there is "TTL=" in every reply ???)

Good, and now for guys trying to search for "TTL" which CAN also result in erroneous response !

Here is the CAN case :

quote:
C:\WINNT\system32>ping 10.134.126.20

Pinging 10.134.126.20 with 32 bytes of data:

Reply from 10.63.4.133: TTL expired in transit.
Reply from 10.63.4.133: TTL expired in transit.
Reply from 10.63.4.133: TTL expired in transit.
Reply from 10.63.4.133: TTL expired in transit.

As you might see there is in fact a TTL to be found but that doesn't mean that you get reply from the machine you pinged !

so 'TTL=' is it (for any MS OS you can imagine !)

[Mad]

{edit}Oh yeah ! 'Request timed out' is also nonsense :

quote:
C:\WINNT\system32>ping xyz
Bad IP address xyz.

would return 'reply' [Roll Eyes]
{/edit}

[ 19. March 2003, 09:32: Message edited by: jpols ]


NTDOCAdministrator
(KiX Master)
2003-03-19 09:49 AM
Re: The correct format.

Jochen... dude, you need to fire up a Windows 95 client and try a ping to a valid address that is not responding.

You will see: Request timed out

in the result on the console. I said nothing about NT/2000/XP this test is ONLY for Windows 95

I might assume that 98 responds the same, not sure about ME as it did add some minor new stuff that 2000 has.


JochenAdministrator
(KiX Supporter)
2003-03-19 09:54 AM
Re: The correct format.

Sorry , I have none ...

Ok, still valid is that from at least NT 3.x upwards there is no other way than finding "TTL=" for reply from pinged machine.
But Ron, don't you accept that 'request timed out' is out of the loop (if one likes to provide a global valid solution) as for the possible 'BAd Ip Address' one always can have due to resolution problems, especially with WINS ?

[Razz] [Razz] [Razz]

Anyway, if my little time allows I will test this evening from my daughters ME installation

[ 19. March 2003, 09:57: Message edited by: jpols ]


NTDOCAdministrator
(KiX Master)
2003-03-19 10:37 AM
Re: The correct format.

hmmm... not sure you can have a GLOBAL 1 size fits all piece of code here. The returned text on Windows 95 is not the same as NT/2000/XP

I also think that ME does show similar to 2000

The start of this topic was about the guy wanting to get a response from Win9x. We all know NT/2000/XP works just fine. Not that big of a deal, more a request to get an antique OS to return a value to test against.


JochenAdministrator
(KiX Supporter)
2003-03-19 10:47 AM
Re: The correct format.

So , the only question left is :

does this work on a Windows 95 Computer ?



break on

$Computer = "" ; Place here any valid (and online) Computer/IP-Address

shell '%Comspec% /C ping $Computer | find /C "TTL=" > nul'

if @error = 0
    $Computer + " replied to the ping request!" ?
else
    $Computer + " was reported OFFLINE, please verify on console!" ?
endif

get $



agreed ?


NTDOCAdministrator
(KiX Master)
2003-03-19 11:08 AM
Re: The correct format.

Jochen,

Here is what you get from a Windows 95 workstation.
Notice that a valid ping first, then run script... Looks okay.
Then ping an address that times out, ping shows REQUEST TIMED OUT
Then run script... Still says it replied to the ping request even though it DID NOT.
That is because @error is not being set. i.e. There is no %errorlevel% set on
Windows 95, thus this method can not be used.

C:\SCRIPTS>ping 192.168.1.101

Pinging 192.168.1.101 with 32 bytes of data:

Reply from 192.168.1.101: bytes=32 time=1ms TTL=128
Reply from 192.168.1.101: bytes=32 time=1ms TTL=128
Reply from 192.168.1.101: bytes=32 time=1ms TTL=128
Reply from 192.168.1.101: bytes=32 time=1ms TTL=128

C:\SCRIPTS>kix32 9x2.kix
192.168.1.101 replied to the ping request!

C:\SCRIPTS>ping 139.104.117.95

Pinging 139.104.117.95 with 32 bytes of data:

Request timed out.
Request timed out.
Request timed out.
Request timed out.

C:\SCRIPTS>kix32 9x2.kix
139.104.117.95 replied to the ping request!


JochenAdministrator
(KiX Supporter)
2003-03-19 11:13 AM
Re: The correct format.

Ouch !

Ok ... then there is no valid method for 95 (except maybe some fancy wsh methods [Roll Eyes] ) as it'd also fail on 'request timed out' (if i got that correctly it does not set errorlevel in any case) [Frown]

So Microcyb ...

TASK = Declare all networked 9x machines as Gameboys (Be a man, accept the facts !) [Big Grin]


JochenAdministrator
(KiX Supporter)
2003-03-19 11:17 AM
Re: The correct format.

Hey !

Not to forget that my statement about "TTL=" is still valid for all (MS) NON-9x OS [Wink]

Quod Erat Demonstrandum !


LonkeroAdministrator
(KiX Master Guru)
2003-03-20 12:22 AM
Re: The correct format.

k, now as we got this far, I would suggest that all who want to make the ping work, use Ping() UDF