2
Nice afternoon to everyone!!! : D I am creating a php page that informs me my local ip, I am doing this through the command: shell_exec('ipconfig')
so far so good because it returns the ip of my machine right, but it does not return only the ip, but also Address Ipv6, Ipv4, subnet mask, Gateway... finally returns the whole class there as when we type the command ipconfig
at PC Command Prompt.
Here’s my dilemma! I want him to print on the screen just the Ip, but he’s printing a list and in the middle of this list is my ip. So the brilliant mind here thought that I could print only ip if the list was an array, assign the value returned by the command to an array variable and print the variable and the obvious happened, it printed:
Array ( [0] => a turminha toda do resultado do comando ipconfig e blá blá blá )
all my list is at index 0. I wonder if there is a way to divide the array, to print only ip or if there is another way to print only ip from this list.
Thank you, if anyone knows, I’d be most grateful :)
There goes the code:
<!DOCTYPE html>
<html>
<head>
<title>teste</title>
<META HTTP-EQUIV="Refresh" CONTENT="60">
</head>
<body>
<?php
$str = array(shell_exec('ipconfig'));
print_r($str);
?>
</body>
</html>
Ever tried to use
$_SERVER['SERVER_ADDR']
instead ofipconfig
?– stderr
Thanks @zekk already tried but did not work it returns ::1
– Sarah