Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Connect to the Internet from the command line UNIX
I like OS X's Aqua interface; I think it's great. But I also think that the terminal, or CLI (command line interface), is very useful. It can be used to autoate an action for further use, to get something done at a distance, or to get something done from single-user mode. One of the things that I wanted most to do was to connect to the Internet via the CLI. I looked but there seemed no way. Eventually by running a command I got from a hint, ps axww, I was able to identify the command that ran when you pressed the connect button of the system-wide menu. Ok, so here it is.

I am using my internal modem and my local dialup, so your settings will be different. Of course this only works with the dial-up. The command for faster connections I need to find out. Here's how I connect from the CLI:
pppd serviceid 1 \
 plugin /System/Library/SystemConfiguration/PPPController.bundle/
   Contents/PlugIns/PPPDialogs.ppp logfile /tmp/ppp.log plugin \
 PPPSerial.ppp device modem modemscript "Apple Internal 56K Modem (v.92)" \
 nomodemsound modemreliable modemcompress modemtone \
 modemdialmode 1 remoteaddress 1234567890 lcp-echo-interval 10 \
 lcp-echo-failure 4 mru 1500 mtu 1500 receive-all 0:0 noipdefault \
 ipcp-accept-local ipcp-accept-remote noauth user myusername \
 password mypassword forcedetach noccp looplocal noaskpassword \
 call myprovider

/usr/libexec/CCLEngine -l 1 -f \
 "/System/Library/Modem Scripts/Apple Internal 56K Modem (v.92)" \
 -s 0 -e 1 -c 1 -p 0 -d 1 -E -S 150 -I "Internet Connect" \
 -i file://localhost/System/Library/Extensions/PPPSerial.ppp/
    Contents/Resources/NetworkConnect.icns \
 -C Cancel - 1234567890
Replace myusername with the username you use to connect, mypassword with the password, and 1234567890 with the actual number. There are oviously many options which I have that you might not want or whatever. So simply set up your dialing options in the Finder, press Connect and then run ps axww once while it's dialing and once while it's connecting. Stick these commands in a script and save it as goconnect or something. Now logout and log in as console, log in again, and run the script. Then you can use lynx as a browser, wget as a downloader, and sendmail as a mail handler.

[robg adds: In the above two commands, I had to break two VERY long lines in un-natural ways. In the first command, the line that starts Contents/Plug... is part of the previous line, and should come immediately after the / that ends that line. In the second command, the same is true of the line that starts with Contents/Resources.... After combining those lines, the others should copy and paste fine with the backslashes to join them. I have not tested this one, as I have no dial-up service.]
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)

Connect to the Internet from the command line | 2 comments | Create New Account
Click here to return to the 'Connect to the Internet from the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Connect to the Internet from the command line
Authored by: Dale Mox on Sep 29, '03 01:42:45PM

Oops, sorry. I forgot to add that "myprovider" at the end of the first command stands for the name you gave to the connection.

Dale Mox

[ Reply to This | # ]
Connect to the Internet from the command line
Authored by: floop on Sep 30, '03 01:39:51AM

I too struggled to understand how to initiate a ppp connection from the command line. Actually in my case I have a small C program which uses the modem port to monitor my phone line for a ring. When a ring is detected it connects to the Internet with a system() call using the same command being described. This allows me to access my system remotely via a telephone ring to get it to connect to the Internet.

With that background let me add a few minor additions to this excellent hint. First it is a little more convenient to use

ps axww | grep pppd

That way you only see the items that include "pppd". Second, if you want the modem status in the menu bar to be correct, the serviceid must be correct. This can get out of sync with the command line if you modify your modem/internet settings at a later time. In fact several things can get out of sync so anytime you change your modem/internet settings you may want to update your script.

One final note is that I do not recall needing to invoke CCLEngine as pppd will normally call that as part of its process. Its been some time so I could be mistaken on this.

[ Reply to This | # ]