Script for getting IP and MAC and then send it.

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

Script for getting IP and MAC and then send it.

Post by Basher52 » Wed Dec 16, 2009 5:10 pm

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:82.196.108.169 Bcast:82.196.109.255 Mask:255.255.254.0
and
nameserver 113.180.249.2
nameserver 113.180.248.3

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:82.196.108.169;nameserver:113.180.249.2;nameserver:113.180.248.3

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

//B52


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
Contact:

Post by Void Main » Wed Dec 16, 2009 7:30 pm

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

http://voidmain.is-a-geek.net/files/scr ... ork.sh.txt

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. ./getnetwor.sh eth0). I put some explanation in the comments at the top.

Post Reply