-3

Note: I working this in a Local network only

I'm using a Jio Internet for the scenario. So I have a IPV6 public IP. I can see the Public ipv6 IP is visible on CMD "ipconfig" or "ipconfig /all"

Under "Wireless LAN adapter Wi-Fi:" I can see two fields as below: IPV6 Address, Temporary IPV6 Address

I get the Temporary IPV6 Address when I search "myip" on Google or on "whatismyipadddress"

Now, How do I extract that data(ie, Temporary IPV6 Address) from Shell and print using PHP ?

Note: I'll be working this such that getting information mentioned above using PHP when I click a Button on a webpage. I should be retrieving this information of a client who is accessing my server and, I will be creating logs with some more datas in my project.

Daniel Raj
  • 11
  • 1
  • 4
  • The IP address of the other host is in the Source Address field of the IP packet that you receive from the other host. That will be the temporary address, which is used in order to provide privacy for the sending host. Search for IPv6 Privacy extensions and random addressing. – Ron Maupin Nov 11 '17 at 16:57
  • 1
    You are asking something for which you already have the answer in your own machine. The IPv6 address of the sending host is in the Source Address filed of the IP packet you received from the host. You may have an [X-Y Problem](https://meta.stackexchange.com/q/66377/369973). – Ron Maupin Nov 11 '17 at 17:12

1 Answers1

0

Assuming its Linux Env. Try this.

<?php
   $ip = shell_exec("/sbin/ifconfig  | grep 'inet:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'");
   echo $ip;
?>

Run this file from CLI $php ip.php

or you can create a bash file first.

#!/bin/bash

/sbin/ifconfig | grep 'inet:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'

and then

<?php

$ip = shell_exec('/path/to/shell/script');
print $ip;

?>

The CLI version of PHP has access to your PATH environment variable.

For windows. try this

<?php
exec("ipconfig.exe",$output_array,$return_val);
echo "Returned $return_val <br><pre>";
foreach ($output_array as $o)
{
echo "$o <br>";
}
echo "</pre>";
?>


<?php
echo exec('ipconfig');
$info = system('ipconfig /all');
echo $info;
?>

See which one fits your scenario ipconfig or ipconfig /all

Robus
  • 465
  • 6
  • 19