[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Portable way to get my NICs' IPs



On Thu, Oct 27, 2005 at 09:35:23PM +0100, James Keasley wrote:
> ifconfig
> 
> It lives in one of the sbins, usually, so probably isn't in your $PATH

Assume I've already tried the obvious answers. :-) ifconfig
isn't quite portable. See below for FreeBSD's output
("inet [IP address]") and contrast it with Debian's ("inet
addr [IP address]").

Besides, that's all screen-scraping anyway. I want to be
able to use this in a script, and I'd prefer not to mangle
text to get my interfaces. The functions necessary to get a
list of all my interfaces, and get the IPs for all of them,
are almost certainly system calls. I'm sure there's a Perl
function to extract them.

Any ideas?

fxp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        options=8<VLAN_MTU>
        inet 192.168.98.130 netmask 0xffffff00 broadcast 192.168.98.255
        inet6 fe80::2e0:81ff:fe2c:752d%fxp0 prefixlen 64 scopeid 0x1
        inet 192.168.98.131 netmask 0xffffff00 broadcast 192.168.98.255
        inet 192.168.98.132 netmask 0xffffff00 broadcast 192.168.98.255
        inet 192.168.98.133 netmask 0xffffff00 broadcast 192.168.98.255
        inet 192.168.98.134 netmask 0xffffff00 broadcast 192.168.98.255
        inet 192.168.98.135 netmask 0xffffff00 broadcast 192.168.98.255
        inet 192.168.98.136 netmask 0xffffff00 broadcast 192.168.98.255
        inet 192.168.98.137 netmask 0xffffff00 broadcast 192.168.98.255
        ether 00:e0:81:2c:75:2d
        media: Ethernet 100baseTX <full-duplex>
        status: active
bge0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
        options=1a<TXCSUM,VLAN_MTU,VLAN_HWTAGGING>
        ether 00:e0:81:2c:75:9a
        media: Ethernet autoselect (none)
        status: no carrier
bge1: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
        options=1a<TXCSUM,VLAN_MTU,VLAN_HWTAGGING>
        ether 00:e0:81:2c:75:9b
        media: Ethernet autoselect (none)
        status: no carrier
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
        inet 127.0.0.1 netmask 0xff000000
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4


-- 
Stephen R. Laniel
steve@laniels.org
+(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key

Attachment: signature.asc
Description: Digital signature


Reply to: