| Author |
Message |
01micko

Joined: 11 Oct 2008 Posts: 7037 Location: qld
|
Posted: Sun 24 Feb 2013, 18:41 Post subject:
get IP address |
|
Hi
I have this one liner that returns IP address for ethernet, wireless and ppp
| Code: | | /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
_________________ keep the faith .. 
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3845
|
Posted: Mon 25 Feb 2013, 20:32 Post subject:
|
|
Do you need the external (internet) ip address or just the local one?
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
01micko

Joined: 11 Oct 2008 Posts: 7037 Location: qld
|
Posted: Tue 26 Feb 2013, 05:24 Post subject:
|
|
Well, that depends on the interface type . 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/ ?
_________________ keep the faith .. 
|
|
Back to top
|
|
 |
tallboy

Joined: 21 Sep 2010 Posts: 357 Location: Oslo, Norway
|
Posted: Tue 26 Feb 2013, 06:31 Post subject:
|
|
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...
tallboy
_________________ True freedom is a live Puppy on a multisession CD/DVD.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3845
|
Posted: Tue 26 Feb 2013, 17:16 Post subject:
|
|
this may be useful: | Code: | | awk '!/IP/{print "IP" $6 "=" $1}' /proc/net/arp |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
Ibidem
Joined: 25 May 2010 Posts: 262
|
Posted: Tue 26 Feb 2013, 22:29 Post subject:
|
|
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.
|
|
Back to top
|
|
 |
01micko

Joined: 11 Oct 2008 Posts: 7037 Location: qld
|
Posted: Tue 26 Feb 2013, 23:18 Post subject:
|
|
yeah, wifi being the "else" shouldn't matter too much.
I was looking at parsing /proc/net/fib_trie
| Code: | 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)
_________________ keep the faith .. 
|
|
Back to top
|
|
 |
Ibidem
Joined: 25 May 2010 Posts: 262
|
Posted: Fri 15 Mar 2013, 20:43 Post subject:
|
|
I remember now that there's vboxnet0, tun0, and tap0-loopback type setups, but meant for networking with VMs/other such things.
|
|
Back to top
|
|
 |
|