testing an internet connection & speed?

how do you test whether there is an active internet connection, and if possible what the average speed is, or the connection type is?

(without launching an application to do it, like internet connect; that is via standard additions or scripting events or something?)

To see if you have an active connection, you could use this (from the forum sometime back):

set intnt to do shell script "ping -c 1"
tell application "Finder"
	set p to number of paragraphs in intnt
	if p < 5 then
		display dialog "Internet connection is down."
		display dialog "Internet connection is up."
	end if
end tell

You can substitute any other IP Address known to answer pings. Use the network utility to
find out - it might be your own nameserver, for example.

Don’t know how to test your throughput.

Thanks… hopefully that IP is not changing. I’m surprised there isn’t a standard way to do this though.

Here’s another that doesn’t require an address, just a URL:

set theHTML to my get_url("checkip.dyndns.org")
set myIP to word 21 of theHTML

if myIP = "put_yours_here" then
	display dialog "You're up and running"
	display dialog "Not connected"
end if

on get_url(this_url)
	set browser_string to "'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/125.4 (KHTML, like Gecko) Safari/125.9'"
	return do shell script "curl " & (quoted form of this_url) & " -A " & browser_string
end get_url

Don’t “thrash” them, however - that is, don’t do this every two minutes or checkip.dyndns.org might cut you off.

How are you connecting to the internet?

lol… i know when and how I’m connected to the internet. i need a script that can be run and check to see if the person running it has an internet connection, and not execute certain code if there’s no connection active. (ie, not try to initiate a connection.)

that dyndns method is probalby worse than the ping method–it would certainly try to connect to check, no?

But you have not, until now, mentioned that you wanted to test for a connection without initiating one. I’ve been assuming, incorrectly, that you wanted to see whether your ISP was up and running or if your wireless connection was functioning.

sorry… yes, i want to test for an internet connection without initiating one if one is not active.

Mine is a permanent cable connection so I can’t help with PPoE or a dialup account - I don’t know what triggers a Mac to establish one.