Operating System - HP-UX
1833753 Members
2397 Online
110063 Solutions
New Discussion

Re: Method to obtain count of physical interfaces

 
M_107
Occasional Contributor

Method to obtain count of physical interfaces

Hi,

I am able to get information of an interface using /dev/dlpi and get_physical_stat. However I am not able to programatically find the no. of (total count of) physical interfaces on a system.

ID_ifNumber returns 4; but I have only 2 interfaces configured and hence it
should return 3(including loopback)

# netstat -in
Name Mtu Network Address Ipkts Ierrs Opkts Oerrs
Coll
lan0:1 1500 10.0.0.0 10.0.0.1 0 0 0 0 0
lan1 1500 192.168.76.0 192.168.79.233 15528 0 190913 0 0
lan0:2 1500 10.0.0.0 10.0.0.2 36 0 72 0 0
lan0 1500 192.168.76.0 192.168.79.11 3997775 62 1066618 0 0
lo0 4136 127.0.0.0 127.0.0.1 1784 0 1784 0 0

# cat /etc/rc.config.d/netconf
INTERFACE_NAME[0]="lan0"
IP_ADDRESS[0]="192.168.79.11"
SUBNET_MASK[0]="255.255.252.0"
BROADCAST_ADDRESS[0]=""
INTERFACE_STATE[0]=""
DHCP_ENABLE[0]=0

IP_ADDRESS[1]=192.168.79.233
SUBNET_MASK[1]=255.255.252.0
INTERFACE_NAME[1]=lan1
BROADCAST_ADDRESS[1]=192.168.79.255
INTERFACE_STATE[1]=up

What does 4 indicate?. Is there a way to programatically obtain the count of
physical interfaces configured on a system where multiple ip addresses are configured
on an interface.

Thanks and Regards,
M Shetty

7 REPLIES 7
Massimo Bianchi
Honored Contributor

Re: Method to obtain count of physical interfaces

Hi,
I would go with lanscan :)

HTH,
Massimo
Deoncia Grayson_1
Honored Contributor

Re: Method to obtain count of physical interfaces

You could go with a lanscan or ioscan -fnC lan and either will give you how many lan cards you have on your server.
If no one ever took risks, Michelangelo would have painted the Sistine floor. -Neil Simon
Steven E. Protter
Exalted Contributor

Re: Method to obtain count of physical interfaces

ioscan -fnC lan

Will list the interfaces. You cn manipulate this to get a count.

number=$(lanscan | grep -v Hardware | grep -v State | wc -l)

echo "NIC cards: $number"

That gets you a good count.

The last iten on the netstat is your loopback. Its needed for networking to work properly.

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
Alzhy
Honored Contributor

Re: Method to obtain count of physical interfaces

As a general rule, do not plainly rely on "lanscan".

Instead use:
ioscan -kfnC lan

Why - if you've APA - it will not tell you how may physical NICs are in that APA aggregate:

# lanscan
Hardware Station Crd Hdw Net-Interface NM MAC HP-DLPI DLPI
Path Address In# State NamePPA ID Type Support Mjr#
0/0/0/0 0x00306E2CC6EF 0 UP lan0 snap0 1 ETHER Yes 119
0/5/0/0 0x0060B05846D2 1 UP lan1 3 FDDI Yes 119
1/10/0/0 0x00306EF23A17 4 UP lan4 snap4 6 ETHER Yes 119
LinkAgg0 0x00306EF23A2C 900 UP lan900 snap900 9 ETHER Yes 119
LinkAgg1 0x00306E0ED6B9 901 UP lan901 snap901 10 ETHER Yes 119
LinkAgg2 0x000000000000 902 DOWN lan902 snap902 11 ETHER Yes 119
LinkAgg3 0x000000000000 903 DOWN lan903 snap903 12 ETHER Yes 119
LinkAgg4 0x000000000000 904 DOWN lan904 snap904 13 ETHER Yes 119

but you can also do:

# lanscan -q
0
1
4
900 3 2
901 5 6
902
903
904


Hakuna Matata.
Patrick Wallek
Honored Contributor

Re: Method to obtain count of physical interfaces

It appears that it is counting your virtual interfaces as well.

I see that you have: lan0, lan0:1, lan0:2 and lan1

So that would make 4 interfaces. I would think it is probably not counting lo0.
Alzhy
Honored Contributor

Re: Method to obtain count of physical interfaces

I would have to add (an APA tour for others) - in my example - the system actually has 6 Physical NICS. 4 NICs are actually used as APA pairs 900 and 901.

APA 900 use lan3 and lan2
APA 901 use lan5 1nd lan6

The three remaining ports lan0, lan1 and lan4 - are unused.
Hakuna Matata.
M_107
Occasional Contributor

Re: Method to obtain count of physical interfaces

Hi,

Thanks for the response.

But I want to do it through a program in C.

Don't want a command

Thanks and Regards,
M Shetty