Thematic background picture
          about Linux

Just a quick note about network connections

Linux, Vineyard
~0 minutes 1 comment

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('nn'):
		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)?

All content © 2007-2025 Christian Dannie Storgaard except where otherwise noted. All rights reserved.
Icons from the Tabler Icons project used under the MIT License.