get IP address

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

get IP address

#1 Post by 01micko »

Hi

I have this one liner that returns IP address for ethernet, wireless and ppp

Code: Select all

/sbin/ifconfig|grep -iE 'Bcast|P-t-P'|tr -s ' '|tr ' ' ':'|cut -d ':' -f4
This is accurate for eth0 (or 1,2 etc), wlan0 (1, etc) and ppp. Is there any other cases I need to cover and if so what?

Oh, and the reason it calls the full path to ifconfig is that /sbin is not usually in an ordinary user's path. (works in debian, slackware).

TIA
Puppy Linux Blog - contact me for access

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#2 Post by technosaurus »

Do you need the external (internet) ip address or just the local one?
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#3 Post by 01micko »

Well, that depends on the interface type :wink: . I only need the dhcp (or statically) assigned address, which ifconfig shows just fine with that simple oneliner.

What I was really getting at is there any other abbreviation for "eth", as in some wireless (usually wlan${n}) can be rao4{n}, ath${n}, I've seen some others IRCC. Not so important for wireless as it is in the "else" bit. "eth" is the "if", ppp is the "if else". And is there anything else similar to ppp that might get lost?

"lo" is already filtered out. So really, the question is what else, if anything, can be found in /sys/class/net/ ?
Puppy Linux Blog - contact me for access

User avatar
tallboy
Posts: 1760
Joined: Tue 21 Sep 2010, 21:56
Location: Drøbak, Norway

#4 Post by tallboy »

Hi 01micko
LupuPlus 5.2.8: Menu -> System -> System status and config -> Pup-SysInfo system information -> System-Apps -> Network, and voilá!
Or just 'ipinfo' in a terminal.

On the other hand, it don't invoke any of the little grey ones... :lol:

tallboy
True freedom is a live Puppy on a multisession CD/DVD.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#5 Post by technosaurus »

this may be useful:

Code: Select all

awk '!/IP/{print "IP" $6 "=" $1}' /proc/net/arp
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

Ibidem
Posts: 549
Joined: Wed 26 May 2010, 03:31
Location: State of Jefferson

#6 Post by Ibidem »

With madwifi you don't want wifi[0-9]* - only ath[0-9]* is actually used.
In theory, it's possible to assign completely arbitrary names.

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#7 Post by 01micko »

yeah, wifi being the "else" shouldn't matter too much.

I was looking at parsing /proc/net/fib_trie

Code: Select all

awk '/LOCAL/{print x};{x=$2}' /proc/net/fib_trie
link
127.0.0.1
192.168.1.18
Was the best I could come up with, but there is no interface there.

Works with ppp too

# awk '/LOCAL/{print x};{x=$2}' /proc/net/fib_trie|grep -vE '[a-z]|^127'
101.118.6.XXX (obfuscated)
Puppy Linux Blog - contact me for access

Ibidem
Posts: 549
Joined: Wed 26 May 2010, 03:31
Location: State of Jefferson

#8 Post by Ibidem »

I remember now that there's vboxnet0, tun0, and tap0-loopback type setups, but meant for networking with VMs/other such things.

Post Reply