Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 18 Sep 2014, 16:05
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
get IP address
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [8 Posts]  
Author Message
01micko


Joined: 11 Oct 2008
Posts: 7802
Location: qld

PostPosted: 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

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Mon 25 Feb 2013, 20:32    Post subject:  

Do you need the external (internet) ip address or just the local one?
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7802
Location: qld

PostPosted: Tue 26 Feb 2013, 05:24    Post subject:  

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/ ?

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
tallboy


Joined: 21 Sep 2010
Posts: 442
Location: Oslo, Norway

PostPosted: 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... Laughing

tallboy

_________________
True freedom is a live Puppy on a multisession CD/DVD.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Tue 26 Feb 2013, 17:16    Post subject:  

this may be useful:
Code:
awk '!/IP/{print "IP" $6 "=" $1}' /proc/net/arp

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
Ibidem

Joined: 25 May 2010
Posts: 489
Location: State of Jefferson

PostPosted: 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
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7802
Location: qld

PostPosted: 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)

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
Ibidem

Joined: 25 May 2010
Posts: 489
Location: State of Jefferson

PostPosted: 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
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [8 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0579s ][ Queries: 11 (0.0090s) ][ GZIP on ]