Just a quick note about network connections

14Mar10

I’ve been working on some new functionality for Vineyard and I needed to test if the user is connected to the internet or not. After some Google scouting I didn’t come up with anything that did what I needed so I ended up writing this little function and thought it might be useful for others.

def test_internet_connection():
	info = subprocess.Popen(['ifconfig', '-a'], stdout=subprocess.PIPE).communicate()[0]
	for interface in info.split('\n\n'):
		if 'UP BROADCAST RUNNING' in interface and 'inet addr:' in interface:
			return True
	return False

Internet connection… Vineyard… what could I be up to? Any guesses (or requests)?

Advertisements


One Response to “Just a quick note about network connections”

  1. 1 Luke Benstead

    I’m hoping that it’s AppDB integration (e.g. show the rating, report a new test etc.) πŸ˜‰


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: