Connect to the Internet from the command line

Sep 29, '03 09:12:00AM

Contributed by: Dale Mox

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.]

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030927023429731