Entry
How do I read the status of the ISDN channels under Linux?
Mar 28th, 2001 13:39
Christopher Arndt,
You have to install isdn4linux for getting ISDN to work (normally
included in every recent distribution). This provides the device file
'/dev/isdninfo', see the manpage isdninfo(4)
I have included an example script that reads the info from this device,
parses the information into a dictionary with 6 keys, corresponding to
the tags of the 6 lines from the file. Every key holds the data as a
list of strings.
The script uses this data, to determine if a given channel is currently
active (i.e connected to the Provider -- probably your internet
connection).
#!/usr/bin/env python
import string, sys
ISDN_USAGE_NONE = 0
ISDN_USAGE_RAW = 1
ISDN_USAGE_MODEM = 2
ISDN_USAGE_NET = 3
ISDN_USAGE_VOICE = 4
ISDN_USAGE_EXCLUSIVE = 64
ISDN_USAGE_OUTGOING = 128
def die(err_string, exit_code=1):
"""Prints error message to stderr and exits with exit code =
exit_code."""
sys.stderr.write("%s\n" % err_string)
sys.exit(exit_code)
if __name__ == '__main__':
try:
f = open('/dev/isdninfo')
except IOError:
die("Could not open ISDN information device '/dev/isdninfo'.",
255)
try:
channel = int(sys.argv[1])
except IndexError:
channel = 0
except ValueError:
die("Please specify channel number as integer.", 255)
info = {}
for i in range(6):
tag, value = string.split(f.readline(), ':', 1)
value = string.split(value)
info[tag] = value
f.close()
if int(info['usage'][channel]):
print "ISDN channel #%02i is active." % channel
sys.exit(0)
else:
print "ISDN channel #%02i is inactive." % channel
sys.exit(1)