Home     My Faqts     Contributors     About     Help    

faqts : Computers : Programming : Languages : Python

FAQTs repaired & updated!
Thanks for your patience...
Entry Add Entry Alert - Edit this Entry

Did You Find This Entry Useful?

8 of 9 people (89%) answered Yes
Recently 8 of 9 people (89%) answered Yes

How do you DIAL a modem in Linux/Windows?

Sep 19th, 2002 04:59

Christopher Arndt, Joe Cavolo
http://www.heise.de/ct/faq/result.xhtml?url=/ct/faq/hotline/01/04/09.shtml&words;=DF%DC%20Netzwerk


Well, it depends on what do you want to do. Two possibilities:
a) you want to establish an internet connection over a modem line
b) you just want to dial some number with the modem (possibly for
dialing into a terminal server)
a -- Every linux distribution has tools to set up and establish a
dial-up internet connection, most of the time there are commandline
tools too. Just call the commandline tool via os.system(). For example,
Red Hat provides the scripts 'ifup'/'ifdown' as part of the
'initscripts' package. Read the Red Hat manual for more information.
Other distros have similar tools.
Under Windows the tool to use depends on the version you use.
With Windows 9x use:
rundll32 rnaui.dll,RnaDial conn_name
where 'conn_name' is the name of a connection you configured in the
dial-up-network.
With Windows NT/2k use:
rasphone -t conn_name
Option -d with the connection name shuts down the link.
b -- You should be able to talk to the modem directly, if it is
connected to a serial port, by just opening the serial port as a file
object (com = open('dev/modem, 'rb+') ) and writing to it using the
normal file object methods (com.write() ). I don't know about internal
or USB modems.
Under Linux the file name to use is the name of the device file
corresponding to the serial port the modem is attached to. This is
normally either '/dev/ttyS0' or 'dev/ttyS1'. There may also exist a
symbolic link called '/dev/modem' to one of the former.
Under Windows/DOS (dunno 'bout W2000/XP) the file name would be 'COM1:'
or 'COM2:' (note the colon!).
Every Hayes-compatible modem understands a set of commands usually
prefixed by the letters 'AT' (for 'attention') and then some command
letter(s). You can find out about them in your modem manual. The command
for dialing is 'D<number>', e.g. to dial the number 06912345 you would
send the command 'ATD06912345' to the modem (file). The modem will send
back a response code that indicates success or failure.
Programming a dialog with a programm (or here: modem) talking to it via
file streams can be a difficult task due to timing issues and buffers.
Fortunately there is the new 'pexpect' module
(http://pexpect.sourceforge.net/) that is a Python implementation of
 Expect and handles exactly this task.



© 1999-2004 Synop Pty Ltd