1833758 Members
2182 Online
110063 Solutions
New Discussion

lan and card information

 
SOLVED
Go to solution
Gord Moore
Frequent Advisor

lan and card information

I need to collect information about the lan cards in my server. It is being moved, and the network guy at the other end wants to know which cable goes into which slot on the server. I can't seem to find one command that will give me everything: ip address, hardware location, mac id, speed, and full/half duplex.

So far I figure that by using "netstat -i", I will see the active/configured lans and can get the ip addresses. Using the lan id (the single number after lan, I can run "lanadmin -ax #" multiple times to display mac address, speed and half/full duplex. Then to get the hardware address I have to use "ioscan -fnC lan" to list all the cards and try to get the hardware address. From all that output I cut and paste into a list.

Isn't there an easier way?

5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: lan and card information

There really isn't one command.

I use the same tools you do.

lanscan
lanadmin
ifconf

For the purpose of moving equipment, I use labelling indicating what ip address is on what network port. Just print and stick.

Don't like giving bad news, but I don't know a way to do it with one command.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Sridhar Bhaskarla
Honored Contributor

Re: lan and card information

Hi,

Write a small script that matches the outputs of 'lanscan', 'netstat -in' and 'lanadmin'. You will get what you need from those three.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
twang
Honored Contributor
Solution

Re: lan and card information

the script I use to consolidate network info as follows:
#!/usr/bin/sh
# Purpose: laninfo.sh: consolidate network info

# find physical networks
p_nics=`/usr/sbin/lanscan -ia | awk '{print $2","$1}'`

#clean up mac address
for i in $p_nics
do
addr=`echo $i|cut -dx -f 2,2`
o1=`echo $addr|cut -c 1-2`
o2=`echo $addr|cut -c 3-4`
o3=`echo $addr|cut -c 5-6`
o4=`echo $addr|cut -c 7-8`
o5=`echo $addr|cut -c 9-10`
o6=`echo $addr|cut -c 11-12`
clean_addr="${o1}:${o2}:${o3}:${o4}:${o5}:${o6}"
nic=`echo $i|cut -d , -f 1,1`
clean_nics="${nic},${clean_addr} $clean_nics"
done

#add primary ip addresses
for i in $clean_nics
do
nic=`echo $i|cut -d , -f 1,1`
ip=`/usr/sbin/ifconfig $nic 2>/dev/null |grep -s 'inet'|awk '{print $2}'`

nic_mac_ip="${i},${ip:=NONE} ${nic_mac_ip}"
done

#add virtual interfaces, if any
for i in `netstat -in |awk '{print $1}'| grep -s ':'`
do
ip=`/usr/sbin/ifconfig $i|grep -s 'inet'|awk '{print $2}'`
parent=`echo $i|cut -d : -f 1,1 `
vnic="${i},${parent},${ip} ${vnic}"
done

#create output
echo "Device\t IP\t\tMAC\t\t Hostname in /etc/hosts"
echo "-------------------------------------------------------------------------------"
for i in $nic_mac_ip $vnic
do
nic=`echo $i|cut -d , -f 1,1`
mac=`echo $i|cut -d , -f 2,2`
ip=`echo $i|cut -d , -f 3,3`
name=`grep "^${ip}[ ]" /etc/hosts | awk '{print $2}' | sort -u`
printf "%-9s%-15s%-19s %s\n" ${nic} ${ip} ${mac} ${name:=NONE}
done | sort

Steven E. Protter
Exalted Contributor

Re: lan and card information

twang!!!

Great script.

In my book you deserve 20 points.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Gerhard Roets
Esteemed Contributor

Re: lan and card information

Hi Gord

I am with SEP's list of commands here
"lanscan -v" is quite usefull. But there is no be-all and end all. The fun starts if you are using trunked vlans to your machine ;)

I took twangs script and added in a bit not nearly as gracefull though and it still does not give everything. Twang great script I hope its kewl that I added a bit.

Outputs the following
HWPath Device IP MAC Hostname in /etc/hosts
-------------------------------------------------------------------------------
0/0/0/0 lan0 NONE 00:30:6E:1C:30:93 NONE
0/6/0/0 lan1 192.6.2.1 00:30:6E:0F:99:1D NONE


#!/usr/bin/sh
# Purpose: laninfo.sh: consolidate network info

# find physical networks
p_nics=`/usr/sbin/lanscan -ia | awk '{print $2","$1}'`

#clean up mac address
for i in $p_nics
do
addr=`echo $i|cut -dx -f 2,2`
o1=`echo $addr|cut -c 1-2`
o2=`echo $addr|cut -c 3-4`
o3=`echo $addr|cut -c 5-6`
o4=`echo $addr|cut -c 7-8`
o5=`echo $addr|cut -c 9-10`
o6=`echo $addr|cut -c 11-12`
clean_addr="${o1}:${o2}:${o3}:${o4}:${o5}:${o6}"
nic=`echo $i|cut -d , -f 1,1`
clean_nics="${nic},${clean_addr} $clean_nics"
done

#add primary ip addresses
for i in $clean_nics
do
nic=`echo $i|cut -d , -f 1,1`
ip=`/usr/sbin/ifconfig $nic 2>/dev/null |grep -s 'inet'|awk '{print $2}'`

nic_mac_ip="${i},${ip:=NONE} ${nic_mac_ip}"
done

#add virtual interfaces, if any
for i in `netstat -in |awk '{print $1}'| grep -s ':'`
do
ip=`/usr/sbin/ifconfig $i|grep -s 'inet'|awk '{print $2}'`
parent=`echo $i|cut -d : -f 1,1 `
vnic="${i},${parent},${ip} ${vnic}"
done

#create output
echo "HWPath\t Device\t IP\t\t\tMAC\t Hostname in /etc/hosts"
echo "--------------------------------------------------------------------------
-----"
for i in $nic_mac_ip $vnic
do
nic=`echo $i|cut -d , -f 1,1`
mac=`echo $i|cut -d , -f 2,2`
ip=`echo $i|cut -d , -f 3,3`
path=`/usr/sbin/lanscan | grep ${nic} | grep -v ${nic}: | awk '{print $1}'`
name=`grep "^${ip}[ ]" /etc/hosts | awk '{print $2}' | sort -u`
printf "%-10s%-9s%-15s%-19s %s\n" $path ${nic} ${ip} ${mac} ${name:=NONE}
done | sort

Regards
Gerhard