Jump to content

$_SERVER['REMOTE_ADDR'] Help


colinireland

Recommended Posts

Hello,

 

I am trying to detemine the MAC address of a machine on a local network from the IP address.

The following code does exactly that.

 

<?php
$IP="192.168.1.18";
exec("ping -c 1 -s 1 $IP");
$mac=exec("/usr/sbin/arp -an | /bin/grep $IP | /usr/bin/awk '{print $4}'");
echo "$IP - $mac";
?>

 

However I need to take the IP address from an HTML form. When using the $_SERVER['REMOTE_ADDR'] variable seems to screw things up for me. Maybe its not the correct type of variable? For example the following will not work.

 

<?php
$IP=$_SERVER['REMOTE_ADDR'];
exec("ping -c 1 -s 1 $IP");
$mac=exec("/usr/sbin/arp -an | /bin/grep $IP | /usr/bin/awk '{print $4}'");
echo "$IP - $mac";
?>

 

Can anyone explain why this is? Our suggest an alternative method of doing this?

 

Regards,

Colin

Link to comment
Share on other sites

Gave that a shot with...

 

<?php
#$IP="192.168.1.18";
$IP=$_SERVER['REMOTE_ADDR'];
var_dump($IP);
?><br /><?php
exec("ping -c 1 -s 1 $IP");
$ans=exec("/usr/sbin/arp -an | /bin/grep $IP | /usr/bin/awk '{print $4}'");
echo "$IP - $ans";
?>

 

and got

 

string(12) "192.168.1.30"
192.168.1.30 -

 

Still no idea why I can't pass it to exec correctly. I'm just trying to get the basic mechanism of getting the mac address in place. Will validate any input at a later stage though.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.