Re: Getting my IP adress (not 127.0.0.1)
| From: | Ignatius Reilly | Date: | Mon, 25 Nov 2002 18:35:48 +0000 |
| Subject: | Re: Getting my IP adress (not 127.0.0.1) | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-17124@lists.php.net to get a copy of this message | ||
I once wrote a script to do just that:
// get W2K ipconfig info:
$text =
ipconfig ; // back ticks, not single quotes
// first extract text block after "PPP"
$needle = "PPP" ;
$a = strstr( $text, $needle ) ;
$a = substr( $a , 0, 180 ) ;
// then extract IP address
$needle = "IP Address. . . . . . . . . . . . : " ;
$a = strrchr( $text, $needle ) ;
$a = substr( $a , 35, 16 ) ;
$new_ip = trim( $a ) ;
Not quite elegant, but efficient (W2K format for ipconfig - I don't know if
it also applies to Windows 98)
(Le bazar me servait à rediriger vers une adresse IP dynamique...)
En espérant avoir été utile...
Ignatius
____________________________________________
----- Original Message -----
From: "Michael Delorme" <michael@delorme.nom.fr>
To: <php-windows@lists.php.net>
Sent: Monday, November 25, 2002 6:52 PM
Subject: [PHP-WIN] Getting my IP adress (not 127.0.0.1)
> Hi
>
> I try to get my local IP adress :
>
> <?php
> $arrIp = gethostbynamel("localhost");
> foreach ($arrIp as $ip) {
> echo $ip."<br />";
> }
> ?>
>
> However I only get 127.0.0.1
> But I want the "public" dynamic adress my ISP gave me, as shown by the
> ipconfig windows command.
>
> Thanks in advance
> M
> _________________________________________
> Michael Delorme
> 41 bd de Brou
> 01000 Bourg-en-Bresse
>
> tel/fax 04 74 23 26 10
> mailto:michael@delorme.nom.fr
> _________________________________________
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>