AutoHotkey Community

It is currently May 26th, 2012, 11:39 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: July 7th, 2009, 9:25 am 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
You're welcome! ;)

That ternary is a kind of a bugfix for the API's return error codes, since all of them are in the 11000+ range except for one. Of course you're right, the 'else' part will invariably be 11000 when errcode is zero and that's how it should've been in the API itself, for easier processing, IMO. I probably got too attached to the ternary operator and got carried away; let's just say it's for readability purposes, maybe nobody else will notice it. :oops:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 7th, 2009, 9:31 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Drugwash wrote:
Hmm, I thought ErrorLevel setting had been covered throughout all subfunctions. :?
I had thought you did not set ErrorLevel except if an error occurred, but I've just noticed that you set ErrorLevel = 0 at the top of each function. However, this is not adequate - each DllCall overwrites ErrorLevel.
Quote:
IcmpSendEcho uses a unique structure to send/receive data and that data is required for success/failure recognition, that is the main reason why the current function is limited to only one request at a time.
I don't think so. IcmpSendEcho only returns once the request is complete, so I don't see how you could use it for multiple simultaneous requests. (That is to say: I think IcmpSendEcho is simply incapable of it, so it doesn't matter what unique structures it uses.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 7th, 2009, 9:55 am 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Lexikos wrote:
[...] each DllCall overwrites ErrorLevel.
Yes and where needed I saved the previous error level to an additional variable and restored the error level before returning. It's possible I might've missed something though; could you please point to such piece of code, if you noticed any?

Edit: Oh, I see your point now... (this coffee doesn't produce the desired effect anymore :? ) I'll make sure the error level gets reset where appropriate, to avoid fake error reporting.
Lexikos wrote:
IcmpSendEcho only returns once the request is complete, so I don't see how you could use it for multiple simultaneous requests. (That is to say: I think IcmpSendEcho is simply incapable of it, so it doesn't matter what unique structures it uses.)
Actually, that is true and I knew it; dunno what I was thinking about, at the time - maybe sending a subsequent request before processing the returned data which would've been wrong anyway. :oops:

Eh, got too much on my plate and sometimes it's confusing to jump from one script to another. Thanks for the additions and corrections. ;)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 9th, 2009, 1:12 am 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
Murp|e> You might want to look at my Server Check script. It does what it sounds like you're wanting to do. You could potentially revise it to use the A_Ping() function listed in this thread (I may do that at some point in time, who knows).

_________________
SilverEdge78


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 18th, 2009, 7:01 pm 
Offline

Joined: March 7th, 2009, 6:44 pm
Posts: 49
Location: Europe, Lithuania
I don't get it... It makes me crazy. I try to use this:
Code:
#Include a_ping.ahk
test := a_ping("192.168.1.254", "test", "1000")
msgbox, %test%

And it don't show me error even if my network cable is unpluged. (192.168.1.254 is my router adress) Btw if I use WWW adress it seems to work OK. Help?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 18th, 2009, 10:00 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
The function returns the address of a struct when ping succeeds and an error message when ping fails.
I have tried the very same piece of code posted above, with the difference that my router's IP is 192.168.2.1 (and I put a Return in the end of the script) and I got Error 11010 when the network cable was disconnected (physically pulled out from the NIC) and the struct address (18874400 in my case) when the cable was plugged in.

I really see no malfunctioning here. Could you please test again? If this thing wasn't working, I suppose there would've been some reports here already. :?

It might not hurt mentioning your software specs, someone with a similar environment may help.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2009, 5:20 pm 
Offline

Joined: March 7th, 2009, 6:44 pm
Posts: 49
Location: Europe, Lithuania
Drugwash wrote:
The function returns the address of a struct when ping succeeds and an error message when ping fails.
I have tried the very same piece of code posted above, with the difference that my router's IP is 192.168.2.1 (and I put a Return in the end of the script) and I got Error 11010 when the network cable was disconnected (physically pulled out from the NIC) and the struct address (18874400 in my case) when the cable was plugged in.

I really see no malfunctioning here. Could you please test again? If this thing wasn't working, I suppose there would've been some reports here already. :?

It might not hurt mentioning your software specs, someone with a similar environment may help.


I noticed that it gives error if i unplug cable and try to ping to my router or any other IP, but if I just disable network connection it shows that ping is OK. (I use last Windows 7 RS)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2009, 6:00 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
I wonder if I should put my paranoia hat on or not. :?

Unless the API is broken in Windows 7 (which BTW I cannot test), this could mean the network connection is still fine and dandy and the user is fooled into thinking it's disabled.

You can write a script that shows the actual data returned by the reply and see if it matches the sent data; if it does, then the connection is definitely still up, at least for a certain range of ports/APIs. Deceiving, to say the least and one of the reasons of my using Win98SE. :evil:

But let's hear from other Win7 users, if any around; I'd be glad to be proven wrong.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 2nd, 2009, 12:27 pm 
On XP, the A_Ping function fails with the following sites:

- www.google.com
- www.yahoo.com
- www.ebay.com
- www.cnn.com
- www.bbc.co.uk

Quote:
Error 11003 [Destination host unreachable] in function IcmpSendEcho


but it works with:

- www.autohotkey.com
- www.wikipedia.com

Why is that?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 2nd, 2009, 12:29 pm 
Ok, nevermind, my bad, they were in my ICMP blocklist :P


Report this post
Top
  
Reply with quote  
PostPosted: October 31st, 2009, 5:41 pm 
Offline

Joined: October 31st, 2009, 4:59 pm
Posts: 14
Hi, thankyou for this ping script. I have been trying to write a small script which: sends a ping to wireless router > checks errorlevel > runs bat script. to disable and then re-enable adapter to restore connectivity if required...

I use remote desktop to my main system from laptop in the bedroom as this means i can spend time with the wife and potter around my system also. My desktop's wireless connection seems to go dead after some time of inactivity or just when it feels, which a quick dash down the hall, and a manual disable/enable rectifies.. hence the need.

The fact your script appears to spit out a reliable errorlevel I think will solve my problem and the fact i will not be bothered by a command prompt window popping up periodically will mean i can increase the ping rate with out being bothered so all in all it sounds great :)

However i seem to be missing something as every time i enter the detals.. "Ping(192.168.0.1,test,30000)" and then run the script i get the error message "The following variable name contains an illegal character: "192.168.0.1""

however if i remove the dots i get no error message but it does not ping the router

My Question: How do I input the address "192.168.0.1" in a manner that will be accepted by the script

Cheers


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2009, 2:50 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Please try to separate function parameters with spaces after commas. Oh and use A_Ping() not Ping().
A_Ping(192.168.0.1, test, 30000)

Also please go to router settings and make sure it allows pings from local hosts - I've recently seen such option in a MSI router.

edit: removed one extra paranthesis and added router tip.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 10th, 2009, 2:18 am 
Offline

Joined: October 31st, 2009, 4:59 pm
Posts: 14
Hi thanks for your reply Drugwash

As it turns out i did not require your a_ping script. Infact i doubt if i really understand exactly what it does however this is what i have used and it seems to work reliably... though no doubt could be better.

It needs devcon.exe to work devcon is available from windows support here:
http://support.microsoft.com/kb/311272

(put in c:\windows\system32 so you can call from the command promt (xp))

My Script is as Follows

Code:
Loop {
   sleep 2000
        RunWait, Ping.exe www.google.com -n 1,,Hide
   sleep 3000
        If not ErrorLevel
   
           {}
   else
   
{
runwait devcon disable pci\ven_168c,,hide ;................... This number is the actual device id located in device manager "pci\ven_168c" (you will need to change this to suit your computer)
runwait devcon enable pci\ven_168c,,hide  ;................... This number is the actual device id located in device manager "pci\ven_168c" (you will need to change this to suit your computer)
sleep 3000
}

     }





what it does
1 runs the windows ping utility (ping.exe)
2 pings google
3 hides the fact its doing this
4 checks if the ping had a reply
5 if it has it waits and does it again in a couple of seconds
5 if there is no connection it disables then enables the network adapter
6 goes back to pinging google every few seconds

Note
because i am only worried about interhousehold connectivity i actually ping my router instead of google as with pinging google i frequently get false negatives resulting in the disableing then enabling of the adapter

was thinking using nslookup instead of ping might be better....


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2009, 2:39 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Your solution has some inconvenience on Win9x machines, namely the ping window being unable to run in hidden mode, which is a major drawback. I also am uncertain whether the devcon application runs on such machines; can't remember ever testing it though. Since I am operating a Win98SE machine, I had to find an alternative solution to this issue.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2010, 7:07 pm 
Offline

Joined: November 20th, 2008, 6:00 pm
Posts: 72
Location: Thionville, France
Hi, pretty useful function, I was looking for something like this, thanks!

I noticed that I get a "Reply buffer too small" error when pinging a non existent host name and it takes longer than just the timeout to give the error. Pinging an existing name works just fine.
I'm getting the error on both Windows 7 Pro X64 and XP Pro X86 so I think it is not linked to my config.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, iDrug, IsNull, Miguel and 42 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group