How to check fast a valid IP address?

hello,

Inside an Applescript I have a shell script


do shell script "curl -X POST -H " & CONTTYP & " -c " & COOKIES & " 'http://" & IPLB & "/authenticate?username=" & USER & "&password=" & MDP & "'"

where IPLB variable is an IP address like this “192.168.1.1”

If IPLB is the good IP, that works fine and fast enough.

When the given IPLB is wrong, the shell command tries 75 times to connect in vain at the address and it takes a lot of time (about 1’30") before it returns curl errors 6 and 7 to handle.
During this time we could think that the applet is down because it doesn’t respond.

Is there a way to get a fast answer that the IP address is not valid?
Thanks!

I apologise, my question wasn’t exactly Applescript relevant and there was a lack of context :wink:

Anyway, I solved the problem as following:
Since the Curl command was to access a box (modem) in administrator mode, a previous rough check is enough to detect if

  1. the box is switched on (error 7 = no route, if the box is off)
  2. the IP is wrong (Curl times out, error 28, if its attempts to connect fail)

to short out the test, just use the -m option with 5 seconds to force curl’s time out


set testIP to do shell script "curl -m 5 http://" & IPLB