LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories
User Name
Password
LinuxQuestions.org Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.

Notices


Reply
  Search this Thread
Old 01-22-2004, 12:31 AM   #1
frandalla
Member
 
Registered: Oct 2003
Location: Tokyo - Japan
Distribution: Slackware
Posts: 348
Blog Entries: 1

Rep: Reputation: 37
After some hard time, a script to return your IP


I don't know if people will find this interesting, but I got so excited I needed to share this with you guys... I needed a script to return me only my ip in a determined interface, but I didn't know anything about awk... so, I got some reading on man awk and after a long and hard time I came up with this :

code - Script name: getmyip

#! /bin/sh
DEV=$1
if [ ! $DEV ]; then
DEV=eth1
fi
IP=`ifconfig | grep $DEV -A 1 | grep "inet addr" | awk '/addr/ {FS = ":"; split($2,a,":"); print a[2]}'`
echo "$IP"

end code


Just put that on my /usr/bin and when I need my ip address just type getmyip eth1 for my NAT ip and getmyip ppp0 for my internet IP (PPPoE dsl)

hope this can be helpful... If anyone has a better and easier solution please! tell me
 
Old 01-22-2004, 09:28 AM   #2
bhaskie
Member
 
Registered: Jan 2004
Location: New Delhi, India
Distribution: L.F.S 5.0 | FreeBSD 5.2 | Debian sid | Gentoo 2004.0 | Slackware 9.1
Posts: 78

Rep: Reputation: 15
This will get ur IP without needing to know awk:
# ifconfig | grep eth0 -A 1 | grep addr: | cut -d : -f 2 | cut -d " " -f 1
 
Old 01-22-2004, 10:06 AM   #3
frandalla
Member
 
Registered: Oct 2003
Location: Tokyo - Japan
Distribution: Slackware
Posts: 348

Original Poster
Blog Entries: 1

Rep: Reputation: 37
Hey, Thanks! Not really used to commands like cut and paste...

Last edited by frandalla; 01-23-2004 at 05:47 PM.
 
Old 01-29-2004, 01:15 PM   #4
Crazed123
Member
 
Registered: Jul 2003
Location: You'll never take me alive!!!!!
Distribution: Snootix
Posts: 73

Rep: Reputation: 15
Or you could type 'hostname -i'.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can a C function return value to Shell Script variable yarnar Programming 17 06-02-2010 05:54 PM
return value from shell script to c code? khucinx Programming 1 05-13-2004 03:43 PM
Is it possible to return variables from a script? pedrosan Linux - Newbie 6 04-20-2004 05:51 AM
dash every time i hit enter (carriage return) in gnome (rh 9) lynchmob09 Linux - Software 1 09-18-2003 12:38 AM
return key on shell script chupacabra Programming 2 10-22-2002 12:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories

All times are GMT -5. The time now is 08:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration