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 Sat 25 Oct 2014, 09:27
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 Posts_count  
Author Message
01micko


Joined: 11 Oct 2008
Posts: 7836
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_website 
technosaurus


Joined: 18 May 2008
Posts: 4353

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: 7836
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_website 
tallboy


Joined: 21 Sep 2010
Posts: 447
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: 4353

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: 501
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: 7836
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_website 
Ibidem

Joined: 25 May 2010
Posts: 501
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:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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