delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/05/07/05:32:19

From: dbe AT wgn DOT net ($Bill Luebkert)
Subject: Re: Finding Out My Own IP-Address
7 May 1998 05:32:19 -0700 :
Message-ID: <355152A4.7292585D.cygnus.gnu-win32@wgn.net>
References: <199805062058 DOT NAA06618 AT cygnus DOT com>
Mime-Version: 1.0
To: Oliver Copp <lyger AT fh-landshut DOT de>
Cc: gnu-win32 AT cygnus DOT com

Oliver Copp wrote:
> 
> Hi !
> 
> Is there a function which allows me to find out my current IP address ?
> 
> My best guess was to use gethostbyname("localhost") but that always returns
> 127.0.0.1.
> 
> When I dial in to my provider via NT-RAS, I'm assigned a dynamic IP address -
> which is what I'm trying to find out.

How about:

$name = (gethostbyname ("localhost"))[0];
$addr = (gethostbyname ($name))[4];
printf "%s\n", join ('.', unpack ("C4", $addr));

Works for me (Win95a, GS Perl).
-- 
  ,-/-  __      _  _         $Bill Luebkert
 (_/   /  )    // //       DBE Collectibles
  / ) /--<  o // //      http://www.wgn.net/~dbe/
-/-' /___/_<_</_</_    Mailto:dbe AT wgn DOT net
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019