Re: How to determine local IP

1999-06-23 Thread John Pearson

It may not be pretty, but this will be faster:
ifconfig | \
awk '/inet addr:/ {sub(.*:,,$2) ; if ($2 !~ /^127/) { print $2 }}'

On Tue, Jun 22, 1999 at 10:34:23PM +1000, Shao Zhang wrote
 What about this one??
 
 ifconfig | \
 grep inet addr | \
 grep -v 127.0.0.1 | \
 awk '{print $2;}' | \
 awk -F':' '{print $2;}'
 
 
 On Mon, Jun 21, 1999 at 11:23:29PM -0500, R. Brock Lynn wrote:
  scratch wrote:
   
   On Mon, 21 Jun 1999, R. Brock Lynn wrote:
   
 /sbin/ifconfig | grep P-t-P | cut -d: -f2 | cut -d  -f1
   
nice, now can you do that with a perl one-liner? :)
   
   Something like this?
   perl -e 'print (`/sbin/ifconfig` =~ /inet addr:(.*?)\s/);'
  
  oohh nifty. Now let's see if I can figure out how it works. :)
  (no don't tell me now! I took the usenix perl tutorials... I should know... 
  :\
  
  --Brock

Each command in the pipeline requires a fork and exec, so the fewer commands
the better.  Since I'm bored, some stats:

Time for a null command (:) in a subshell:
real0m0.019s
user0m0.010s
sys 0m0.010s

Time for running ifconfig in a subshell:
real0m0.236s
user0m0.160s
sys 0m0.030s

Time for Shao Zang's pipeline, in a subshell:
real0m0.274s
user0m0.210s
sys 0m0.020s

Time for my pipeline, in a subshell:
real0m0.243s
user0m0.190s
sys 0m0.000s

Time for lunch,


John P.
-- 
[EMAIL PROTECTED]
[EMAIL PROTECTED]
Oh - I - you know - my job is to fear everything. - Bill Gates in Denmark


Re: How to determine local IP

1999-06-22 Thread R. Brock Lynn
scratch wrote:
 
 On Mon, 21 Jun 1999, R. Brock Lynn wrote:
 
   /sbin/ifconfig | grep P-t-P | cut -d: -f2 | cut -d  -f1
 
  nice, now can you do that with a perl one-liner? :)
 
 Something like this?
 perl -e 'print (`/sbin/ifconfig` =~ /inet addr:(.*?)\s/);'

oohh nifty. Now let's see if I can figure out how it works. :)
(no don't tell me now! I took the usenix perl tutorials... I should know... :\

--Brock

-  PGP key ID: FED76A3D [EMAIL PROTECTED] 4 / 5 / 1999

   __ _Debian GNU   R. Brock Lynn [EMAIL PROTECTED]
  / /(_)_ __  _   ___  __   http://www.debian.org/ irc.openprojects.net
 / / | | '_ \| | | \ \/ /  'Free Software'
/ /__| | | | | |_| | Remember that's Free as in Freedom, not Free as
\/_|_| |_|\__,_/_/\_\   in price!   Debian's the Greatest!


Re: How to determine local IP

1999-06-22 Thread Brad
On Mon, 21 Jun 1999, scratch wrote:

 On Mon, 21 Jun 1999, R. Brock Lynn wrote:
 
   /sbin/ifconfig | grep P-t-P | cut -d: -f2 | cut -d  -f1
  
  nice, now can you do that with a perl one-liner? :)
 
 Something like this?
 perl -e 'print (`/sbin/ifconfig` =~ /inet addr:(.*?)\s/);'

Beat me to it! Oh well, i can clean it up to make it work right...
perl -e 'print (`/sbin/ifconfig` =~ /inet addr:(.*?)\s P-t-P:/, \n);'

Or how about one for every interface? This seems to work...
perl -e 'for(`/sbin/ifconfig`){/^\S+/ and $i=$ or /inet addr:(\S+)/ and 
print$i\t$1\n}'

If you don't want the interface name, it gets even shorter:
perl -e 'for(`/sbin/ifconfig`){/inet addr:(\S+)/ and print$1\n}'



Re: How to determine local IP

1999-06-22 Thread Brian Servis
*- On 21 Jun, Brad wrote about Re: How to determine local IP
 On Mon, 21 Jun 1999, scratch wrote:
 
 On Mon, 21 Jun 1999, R. Brock Lynn wrote:
 
   /sbin/ifconfig | grep P-t-P | cut -d: -f2 | cut -d  -f1
  
  nice, now can you do that with a perl one-liner? :)
 
 Something like this?
 perl -e 'print (`/sbin/ifconfig` =~ /inet addr:(.*?)\s/);'
 
 Beat me to it! Oh well, i can clean it up to make it work right...
 perl -e 'print (`/sbin/ifconfig` =~ /inet addr:(.*?)\s P-t-P:/, \n);'
 
 Or how about one for every interface? This seems to work...
 perl -e 'for(`/sbin/ifconfig`){/^\S+/ and $i=$ or /inet addr:(\S+)/ and 
 print$i\t$1\n}'
 
 If you don't want the interface name, it gets even shorter:
 perl -e 'for(`/sbin/ifconfig`){/inet addr:(\S+)/ and print$1\n}'
 

I HAVE to learn Perl  These are sooo much faster than the
grep/awk/cut hacks that I and others have thrown out in this thread. I
love *nix and all its tools.

-- 
Brian 
-
Mechanical Engineering  [EMAIL PROTECTED]
Purdue University   http://www.ecn.purdue.edu/~servis
-


Re: How to determine local IP

1999-06-22 Thread Shao Zhang
What about this one??

ifconfig | \
grep inet addr | \
grep -v 127.0.0.1 | \
awk '{print $2;}' | \
awk -F':' '{print $2;}'


On Mon, Jun 21, 1999 at 11:23:29PM -0500, R. Brock Lynn wrote:
 scratch wrote:
  
  On Mon, 21 Jun 1999, R. Brock Lynn wrote:
  
/sbin/ifconfig | grep P-t-P | cut -d: -f2 | cut -d  -f1
  
   nice, now can you do that with a perl one-liner? :)
  
  Something like this?
  perl -e 'print (`/sbin/ifconfig` =~ /inet addr:(.*?)\s/);'
 
 oohh nifty. Now let's see if I can figure out how it works. :)
 (no don't tell me now! I took the usenix perl tutorials... I should know... :\
 
 --Brock
 
 -  PGP key ID: FED76A3D [EMAIL PROTECTED] 4 / 5 / 1999
 
__ _Debian GNU   R. Brock Lynn [EMAIL PROTECTED]
   / /(_)_ __  _   ___  __   http://www.debian.org/ irc.openprojects.net
  / / | | '_ \| | | \ \/ /  'Free Software'
 / /__| | | | | |_| | Remember that's Free as in Freedom, not Free as
 \/_|_| |_|\__,_/_/\_\   in price!   Debian's the Greatest!
 
 
 -- 
 Unsubscribe?  mail -s unsubscribe [EMAIL PROTECTED]  /dev/null
 
 

-- 

Shao Zhang - Running Debian 2.1  ___ _   _
Department of Communications/ __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia   |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: [EMAIL PROTECTED]  |___/ 
_


Re: How to determine local IP

1999-06-22 Thread Angus Claydon
 Hi, Once dialed in, how to determine the local (dynamically assigned) IP id? 
 I know pppd invokes ip-up with the local IP. But outside that, is there a env 
 variable, API or a file that holds returns this info?
 
 Thanks much,
 nram

ifconfig

 


Re: How to determine local IP

1999-06-22 Thread Mark Bainter
R. Brock Lynn [EMAIL PROTECTED] wrote:
 John Hasler wrote:
  
  Ramesh Natarajan writes:
   Hi, Once dialed in, how to determine the local (dynamically assigned) IP
   id? I know pppd invokes ip-up with the local IP. But outside that, is
   there a env variable, API or a file that holds returns this info?
  
  Put a script in /etc/ppp/ip-up.d to write the IP to a file.
 
 ifconfig does it for me.

I think John had it right.  Something like:

/etc/ppp/ip-up.d/getip
#!/bin/sh

echo $4  /tmp/ip.num

and then in ~/.shellrc

alias ip='cat /tmp/ip.num'

Then, anytime you want the ip# you can either pull it from the file or use ip
to get it.  Perhaps if I knew what you wanted to do with the number I could
come up with a better way of having it at hand?

-- 
What Arnon refuses to say, probably to stay in the good graces of
Microsoft, is that shaving offmost of NT may be the only way to make the
operating system stable enough to compete with Unix for running
high-availability applications.
-- Robin Hohman, Network World, pg 24


pgpexEyzmoSOf.pgp
Description: PGP signature


How to determine local IP

1999-06-21 Thread Ramesh Natarajan
This message was sent from Geocrawler.com by Ramesh Natarajan [EMAIL 
PROTECTED]

Hi, Once dialed in, how to determine the local (dynamically assigned) IP id? I 
know pppd invokes ip-up with the local IP. But outside that, is there a env 
variable, API or a file that holds returns this info?

Thanks much,
nram

Geocrawler.com - The Knowledge Archive


Re: How to determine local IP

1999-06-21 Thread Ed Kutrzyba

Hi, Once dialed in, how to determine the local (dynamically assigned) IP
id? I know pppd invokes ip-up with the local IP. But outside that, is
there a env variable, API or a file that holds returns this info?

Hi,
Try plog.  It should tell you everything you need to know.
hth,
EK


Re: How to determine local IP

1999-06-21 Thread Rick Macdonald
On Mon, 21 Jun 1999, Ramesh Natarajan wrote:

 This message was sent from Geocrawler.com by Ramesh Natarajan [EMAIL 
 PROTECTED]
 
 Hi, Once dialed in, how to determine the local (dynamically assigned)
 IP id? I know pppd invokes ip-up with the local IP. But outside that,
 is there a env variable, API or a file that holds returns this info?

I would use ip-up to write a file that contains the IP. However, I used to
use the following sometimes. I don't use ppp anymore, but this might
still work. awk can probably do it more elegantly...

/sbin/ifconfig | grep P-t-P | cut -d: -f2 | cut -d  -f1

...RickM...


Re: How to determine local IP

1999-06-21 Thread Andrei Ivanov
 
 This message was sent from Geocrawler.com by Ramesh Natarajan [EMAIL 
 PROTECTED]
 
 Hi, Once dialed in, how to determine the local (dynamically assigned) IP id? 
 I know pppd invokes ip-up with the local IP. But outside that, is there a env 
 variable, API or a file that holds returns this info?
 
 Thanks much,
 nram

Try plog

Andrew


---
 Andrei S. Ivanov  
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 UIN 12402354  
 http://members.tripod.com/AnSIv   --Little things for Linux.
 http://www.missouri.edu/~c680789  --Computer languages of the world
   My work in progress.
---


Re: How to determine local IP

1999-06-21 Thread Ben Collins
On Mon, Jun 21, 1999 at 08:54:03AM -0500, Ramesh Natarajan wrote:
 This message was sent from Geocrawler.com by Ramesh Natarajan [EMAIL 
 PROTECTED]
 
 Hi, Once dialed in, how to determine the local (dynamically assigned) IP id? 
 I know pppd invokes ip-up with the local IP. But outside that, is there a env 
 variable, API or a file that holds returns this info?

# ifconfig ppp0

That command will show you the status of the ppp link.


Re: How to determine local IP

1999-06-21 Thread Brian Servis
*- On 21 Jun, Rick Macdonald wrote about Re: How to determine local IP
 On Mon, 21 Jun 1999, Ramesh Natarajan wrote:
 
 This message was sent from Geocrawler.com by Ramesh Natarajan [EMAIL 
 PROTECTED]
 
 Hi, Once dialed in, how to determine the local (dynamically assigned)
 IP id? I know pppd invokes ip-up with the local IP. But outside that,
 is there a env variable, API or a file that holds returns this info?
 
 I would use ip-up to write a file that contains the IP. However, I used to
 use the following sometimes. I don't use ppp anymore, but this might
 still work. awk can probably do it more elegantly...
 
 /sbin/ifconfig | grep P-t-P | cut -d: -f2 | cut -d  -f1
 

Another hack using awk, not any more elegan just goes to show that there
are more than one way to do things

ifconfig ppp0 | grep inet | awk -F: '{print $2}' | awk -F  '{print $1}'

-- 
Brian 
-
Mechanical Engineering  [EMAIL PROTECTED]
Purdue University   http://www.ecn.purdue.edu/~servis
-


Re: How to determine local IP

1999-06-21 Thread John Hasler
Ramesh Natarajan writes:
 Hi, Once dialed in, how to determine the local (dynamically assigned) IP
 id? I know pppd invokes ip-up with the local IP. But outside that, is
 there a env variable, API or a file that holds returns this info?

Put a script in /etc/ppp/ip-up.d to write the IP to a file.
-- 
John Hasler
[EMAIL PROTECTED] (John Hasler)
Dancing Horse Hill
Elmwood, WI


Re: How to determine local IP

1999-06-21 Thread Alexander S Polyakov




On Mon, 21 Jun 1999, Ramesh Natarajan wrote:

 This message was sent from Geocrawler.com by Ramesh Natarajan [EMAIL 
 PROTECTED]
 
 Hi, Once dialed in, how to determine the local (dynamically assigned) IP id? 
 I know pppd invokes ip-up with the local IP. But outside that, is there a env 
 variable, API or a file that holds returns this info?
 
 Thanks much,
 nram
 
 Geocrawler.com - The Knowledge Archive
 
 
 -- 
 Unsubscribe?  mail -s unsubscribe [EMAIL PROTECTED]  /dev/null
 

 I am using ifconfig as root . From output I will be able to figure out
your dynamic IP . I could also ping yourself to be absolutely sure . If
you can not you need to reconfigure your ppp-conection. 

the best ,
alex.


Re: How to determine local IP

1999-06-21 Thread R. Brock Lynn
John Hasler wrote:
 
 Ramesh Natarajan writes:
  Hi, Once dialed in, how to determine the local (dynamically assigned) IP
  id? I know pppd invokes ip-up with the local IP. But outside that, is
  there a env variable, API or a file that holds returns this info?
 
 Put a script in /etc/ppp/ip-up.d to write the IP to a file.

ifconfig does it for me.

--brock

-  PGP key ID: FED76A3D [EMAIL PROTECTED] 4 / 5 / 1999

   __ _Debian GNU   R. Brock Lynn [EMAIL PROTECTED]
  / /(_)_ __  _   ___  __   http://www.debian.org/ irc.openprojects.net
 / / | | '_ \| | | \ \/ /  'Free Software'
/ /__| | | | | |_| | Remember that's Free as in Freedom, not Free as
\/_|_| |_|\__,_/_/\_\   in price!   Debian's the Greatest!


Re: How to determine local IP

1999-06-21 Thread R. Brock Lynn
Rick Macdonald wrote:
 
 On Mon, 21 Jun 1999, Ramesh Natarajan wrote:
 
  This message was sent from Geocrawler.com by Ramesh Natarajan [EMAIL 
  PROTECTED]
 
  Hi, Once dialed in, how to determine the local (dynamically assigned)
  IP id? I know pppd invokes ip-up with the local IP. But outside that,
  is there a env variable, API or a file that holds returns this info?
 
 I would use ip-up to write a file that contains the IP. However, I used to
 use the following sometimes. I don't use ppp anymore, but this might
 still work. awk can probably do it more elegantly...
 
 /sbin/ifconfig | grep P-t-P | cut -d: -f2 | cut -d  -f1

nice, now can you do that with a perl one-liner? :)

Well it's better than my c utility that does it. But maybe the c utility is a
few nanoseconds faster. :P

--Brock

-  PGP key ID: FED76A3D [EMAIL PROTECTED] 4 / 5 / 1999

   __ _Debian GNU   R. Brock Lynn [EMAIL PROTECTED]
  / /(_)_ __  _   ___  __   http://www.debian.org/ irc.openprojects.net
 / / | | '_ \| | | \ \/ /  'Free Software'
/ /__| | | | | |_| | Remember that's Free as in Freedom, not Free as
\/_|_| |_|\__,_/_/\_\   in price!   Debian's the Greatest!#include sys/ioctl.h
#include sys/socket.h
#include netinet/in.h
#include net/if.h
#include arpa/inet.h

#include unistd.h
#include stdio.h

static struct in_addr device_address(const char *if_name)
{
struct ifreq ifr;
struct sockaddr_in *addr;
int s;

s = socket(PF_INET, SOCK_DGRAM, 0);
if (s == -1)
{
perror(socket);
exit(1);
}

strcpy(ifr.ifr_name, if_name);

if (ioctl(s, SIOCGIFADDR, ifr)  0)
{
perror(ioctl(SIOCGIFADDR));
exit(1);
}

addr = (struct sockaddr_in *) ifr.ifr_broadaddr;

close(s);

return addr-sin_addr;
}

int main(int argc, char **argv)
{
struct in_addr addr;

if (argc  2)
{
fprintf(stderr, Usage: %s interface\n, argv[0]);
exit(1);
}

addr = device_address(argv[1]);

printf(IP Address: %s\n, inet_ntoa(addr));

return 0;
}


Re: How to determine local IP

1999-06-21 Thread scratch
On Mon, 21 Jun 1999, R. Brock Lynn wrote:

  /sbin/ifconfig | grep P-t-P | cut -d: -f2 | cut -d  -f1
 
 nice, now can you do that with a perl one-liner? :)

Something like this?
perl -e 'print (`/sbin/ifconfig` =~ /inet addr:(.*?)\s/);'

--nico ;) 

(yeah you'll probably have to change 'inet addr' to 'P-t-P')

:: Nico Galoppo ::  Linux - Free power for the masses  :  ::  :.
:: ::
::  scratch at ace.ulyssis.student.kuleuven.ac.be  ::
 : http://hq.narfum.org/~scratch  ::
   .   .::