views:

141

answers:

4

I admit the linux network system is somewhat foreign to me, I know enough of it to configure routes manually and assign a static IP if necessary.

So quick question, in the ifconfig configuration files, is it possible to add a post connect hook to a python script then use a python script to reassign a hostname in /etc/hosts and spawn off a new process to do other things once the hostname has been updated.

This is a "fun" project for me to solve an annoyance in my daily routine. When I boot up my workstation in the morning, the DHCP service assigns it a IP at random. So I usually stop what I'm doing, lookup my new IP, type that IP into my laptop and get synergy running so I can share the two machines. I figure I lose 10-15 minutes a day doing this everyday of the week and I've never really messed with linux's networking system so it would ultimately pan out.

I already figured my python script would have to run as root, therefore I'd store it in /root or somewhere else that's safe. I found a similar question on stack overflow that pointed me in the direction of http://www.secdev.org/projects/scapy/index.html a raw packet toolset to work with ARP. Editing the host file is a snap... just wondering what possible side effects of trying to put this hook into a core service might cause.

+1  A: 

Just make sure Avahi / Bonjour's running, then type hostname.local (or also try hostname.localdomain) - it resolves using mDNS, so you don't have to care what your IP is or rigging /etc/hosts.

Paul Betts
A: 

You could also use arp-scan (a Debian package of the name exists, not sure about other distributions) to scan your whole network. Have a script parse its output and you'll be all set.

hillu
+1  A: 

Sorry, it looks like an attempt to create a problem where no problem exists, and subsequently solve it using a bit crazy methods. :)

You can configure your dhcp server (router) to always issue a fixed ip for your workstation. If you don't have dhcp server, then why do you use dhcp for configuring the interface? Change the configuration (/etc/network/interfaces in Ubuntu and Debian) to assign static ip address to the interface.

Eugene Morozov
At home, this would be true, but at my office the office LAN is a low priority... as long as it works their isn't a problem.
David
Also I did say this was a "fun" project, so it goes under the category of borderline useless but possibly fun to do so I learn something new.
David
+1  A: 

Cleanest solution would be to have a DHCP server that exchanges its assignments with a local DNS server. So regardless which IP address your workstation is being assigned to, it is accessible under the same hostname.

This concept is used in every full-blown windows network as well as in any other well configured network.