Fetching Host name and MAC address.. 
June 26th, 2008, 08:52 PM
| | Member | | Join Date: Apr 2008 Location: United states
Posts: 123
| | |
Hey all,
I am trying to make one script which I can run on different computers and give me the hostname as well as the MAC address.
Can you please help me how to do so ??script in Perl or PHP will work...
Thanks..
| 
June 27th, 2008, 12:23 AM
|  | Moderator | | Join Date: Jul 2007 Location: Arkansas
Posts: 901
| | | re: Fetching Host name and MAC address..
Writing the code is going to be up to you. If you have problems we will be glad to help.
Check CPAN for Net::Domain and Net::Mac Perlfaq9
--Kevin
| 
June 27th, 2008, 12:32 AM
| | Member | | Join Date: Apr 2008 Location: United states
Posts: 123
| | | re: Fetching Host name and MAC address.. Quote: |
Originally Posted by eWish Writing the code is going to be up to you. If you have problems we will be glad to help.
Check CPAN for Net::Domain and Net::Mac Perlfaq9
--Kevin | Hi Kevin,
I have written some code , which gives me IP address as well as Host name , but not the MAC address.I am not sure , how can i Get the MAC address of particular IP address using PHP..
My code is , -
<?php
-
<?php
-
echo "IP Address Is : ";
-
echo $_SERVER['HTTP_X_FORWARDED_FOR']; // Show IP
-
-
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
-
-
echo " Host Name : ";
-
echo gethostbyaddr($ip);
-
$mac = returnMacAddress();
-
function returnMacAddress() {
-
-
// Get the arp executable path
-
$location = `which arp`;
-
// Execute the arp command and store the output in $arpTable
-
$arpTable = `$location`;
-
// Split the output so every line is an entry of the $arpSplitted array
-
$arpSplitted = split("\n",$arpTable);
-
// Get the remote ip address (the ip address of the client, the browser)
-
-
$remoteIp = $ip;
-
foreach ($arpSplitted as $value) {
-
// Split every arp line, this is done in case the format of the arp
-
// command output is a bit different than expected
-
$valueSplitted = split(" ",$value);
-
foreach ($valueSplitted as $spLine) {
-
if (preg_match("/$remoteIp/",$spLine)) {
-
$ipFound = true;
-
}
-
// The ip address has been found, now rescan all the string
-
// to get the mac address
-
if ($ipFound) {
-
// Rescan all the string, in case the mac address, in the string
-
// returned by arp, comes before the ip address
-
// (you know, Murphy's laws)
-
reset($valueSplitted);
-
foreach ($valueSplitted as $spLine) {
-
if (preg_match("/[0-9a-f][0-9a-f][:-]".
-
"[0-9a-f][0-9a-f][:-]".
-
"[0-9a-f][0-9a-f][:-]".
-
"[0-9a-f][0-9a-f][:-]".
-
"[0-9a-f][0-9a-f][:-]".
-
"[0-9a-f][0-9a-f]/i",$spLine)) {
-
return $spLine;
-
}
-
}
-
}
-
$ipFound = false;
-
}
-
}
-
return false;
-
}
-
-
| 
June 27th, 2008, 12:38 AM
|  | Moderator | | Join Date: Jul 2007 Location: Arkansas
Posts: 901
| | | re: Fetching Host name and MAC address..
I don't know any PHP and if you prefer PHP I can move your post to the PHP forum. If you want to use perl the checkout the links I provided and then it should be a piece of cake.
--Kevin
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,702 network members.
|