Script for getting IP and MAC and then send it.

Discuss Networking
Post Reply
User avatar
Posts: 930
Joined: Wed Oct 22, 2003 5:57 am
Location: .SE

Script for getting IP and MAC and then send it.

Post by Basher52 »

The first thing I need is something to list the IP and MAC addresses of a network card and it's DNS.
with this I can list it up:

MAC: ifconfig eth0| grep -i HWaddr
IP: ifconfig eth0| grep -i 'inet addr'
DNS: more /etc/resolv.conf | grep -i nameserver

these will get something like this:

eth0 Link encap:Ethernet HWaddr 00:89:66:05:C8:EF
inet addr: Bcast: Mask:

now I just wish I could understand awk so I could get these into one little nice output line as something like:

type:data;type:data... etc

HWaddr:00:89:66:05:C8:EF;inet addr:;nameserver:;nameserver:

and I can even throw in the Bcast and Mask from the IP address too.
Then try to figure out how to send it so a listening service... but thats another thing.

This is the first thing I need help with and if you feel like it, please explain what it is every command are doing :P

The next step is to get this to work on a distro named: Linux MontaVista Pro 3.11. It's a commercial version so I have no info about it, at least what I can find.
A buddy of mine came over two screen with these cards in it and asked me to help him with a script for the above.
I just told him, no way dude :P
but I'm curious anyways lol


UPDATE: I just saw that using a colon to separate the 'type' and 'data' ain't so smart since the MAC address has that, think I have to go with some other "splitter"

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Post by Void Main »

Well there are a million ways you can do it but here is a simple little script I just wrote for you: ...

It should be fairly self explanatory. If you have any questions just ask but you can you can run each command one at a time to see what it does to the output of the 'ip' command. Save the file to your disk, make it executable and run it (e.g. ./ eth0). I put some explanation in the comments at the top.

Post Reply