Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Much easier way' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Much easier way
Authored by: jonbauman on Mar 18, '04 04:33:35PM

There's really no need to go to the trouble of running an application that uses your Internet connection to confirm it's presence. Setting up the TCP connection and all is really unnecessary, since the kernel already knows if it has an active connection; just ask ifconfig. To check if your wired ethernet is connected, just do

(do shell script "ifconfig en0 | awk '/inet/ {print $2}'") is not equal to ""
To check your wireless, change en0 to en1 (probably, it could be different depending on your system config). Other interfaces can be checked similarly. If you want to check for IPv4 only, change /inet/ to /inet /, excluding /inet6/. It's probably apparent how to check for IPv6. As a bonus, you can extract your IP address this way, in case you wanted to use it for something.



[ Reply to This | # ]