I'm trying to tell whether or not I have network access in python. I'm using:
interfaces = os.listdir("/sys/class/net")
for interface in interfaces:
cards = open("/sys/class/net/" + interface + "/operstate", "r");
if cards.read() == "up":
print("network is up")
cards.close()
Which is never true even though adding a 'print(cards.read())' returns up. I've tried adding a newline character to that if statement as well which doesn't help.
If you know of a better way to tell if I have network access that would also be appreciated.