Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
144 lines (129 sloc) 4.79 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>netschemes and netutils: network schemes in Python</title>
<meta content="Akkana Peck" name="author">
<style type="text/css">
pre,code { color: rgb(153, 0, 0); }
.cmd { color: rgb(153, 0, 0); font-weight: bold }
</style>
</head>
<body bgcolor="white" alink="#000099" link="#000099" vlink="#990099">
<img alt="[tux networking]" src="/images/logos/tuxnetwork.jpg"
align="right" height="187" width="256">
<h1>netschemes and netutils</h1>
<h2>Howto Set Up Multiple Network Schemes on a Linux Laptop</h2>
... and ...
<h2>a Python networking utility library</h2>
<p>
As you take your laptop from one network to the next, from home
to work or from the coffee shop to the conference, how do you
tell it about each new network?
<p>
Modern Linux systems come with nifty GUI programs such as
<i>NetworkManager</i> and <i>wicd</i>, but I find them slightly
cumbersome and hard to use. I find they're always trying to
out-guess me about what network I really want to use, and they
don't work terribly well with a lightweight desktop.
<p>
I find it much faster to type one command, like <b>netscheme home</b>
or <b>netscheme work</b>, for networks I use a lot, and save all the
fiddling with menus.
<p>
This page covers two topics:
<ol>
<li><a href="#netscheme"><b>Using</b> the high-level "netscheme" script</a>
<li><a href="#netutils">The <b>Python "netutils.py"</b> network utility module</a>
</ol>
<a name="netscheme">
<h2>Using netscheme</h2>
<p>
You need two Python scripts: <a href="netscheme-1.4">netscheme-1.4</a> and
<a href="netutils-1.4.py">netutils-1.4.py</a>.
Put them somewhere in your path and name them netscheme and netutils.py:
I put them in $HOME/bin, my personal bin directory, but somewhere like
/usr/local/bin is also fine.
<p>
By default, netscheme knows about two schemes.
The first, "dhcp", will try to set up a connection using your first wired
ethernet port (e.g. eth0) and a DHCP address. To use it, type:
<pre>
sudo netscheme dhcp
</pre>
<p>
The second built-in scheme, "wifi", is also DHCP, but uses
your first wireless connection (typically wlan0 or eth1).
This works on some networks, but most wireless networks will require
that you specify a network name (SSID).
<p>
To set up your own custom schemes for places you go, create a file in
your home directory called <b>.netscheme</b> containing entries like this:
<pre>
[home]
dhcp = false
ip = 192.168.1.42
netmask = 255.255.255.0
broadcast = 192.168.1.255
gateway = 192.168.1.1
dns_servers = 192.168.1.1,192.168.1.2
[coffeehouse]
encryption = open
essid = coffeehouse-wifi
[work]
encryption = wpa
essid = MyWorkWPA
key = secretpassword
</pre>
<p>
DHCP is the default, but you can set it to false and use static addresses.
<h3>Usage:</h3>
<p>
<code>netscheme</code> with no arguments will try to figure out the
current scheme. (For a wired scheme with no essid, it may not be sure.)
<p>
<code>netscheme schemename</code> will switch to that scheme.
<p>
<code>netscheme essid</code> will try to connect to the given wireless
network, and will ask whether you want to save that as a scheme for later.
<p>
<b>Options:</b><br>
<table>
<tr><td>--version <td>show program's version number and exit
<tr><td>-h, --help <td>show this help message and exit
<tr><td>-l, --list <td>List the known schemes
<tr><td>-a, --accesspoints <td>List available accesspoints
<tr><td>-m, --multi <td>Add a new interface without bringing down current one
</table>
<a name="netutils">
<h2>netutils.py: a Python module for handling networking</h2>
<p>
netutils.py is the heart of netscheme. It consists primarily of
wrappers around system utilities like <i>ifconfig</i>,
<i>iwconfig</i>, <i>iwlist</i>, <i>route</i>, <i>modprobe</i> and so on,
but it presents a much cleaner Python interface so you don't have to
deal with those underlying details.
<p>
Download it: <a href="netutils-1.4.py">netutils-1.4.py</a>
<p>
Documentation for it (generated with pydoc) is available here:
<a href="netutils-1.4.html">Python netutils.py networking module</a>.
<p>
If you have a wishlist for functions you'd like to see in
netutils.py, or ways you think I should change the API, don't
hesitate to <a href="/mailme.html">let me know!</a>
<h2>Ancient history</h2>
<p>
For historical reasons I've left the
<a href="/linux/networkSchemes-deb.html">Debian/Ubuntu-specific
network schemes</a> page online. It includes some possibly helpful
though also partly obsolete information about Debian's
/etc/network/interfaces mechanism, and maybe even a bit of even more
obsolete information about networking under old Redhat systems.
<hr>
<a href="../">More software</a><br>
<a href="/linux">Linux Links</a><br>
<a href="/">Shallow Sky Home</a><br>
</body>
</html>