467,113 Members | 1,315 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,113 developers. It's quick & easy.

Fetching Host name and MAC address..

100+
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..
Jun 26 '08 #1
  • viewed: 6506
Share:
3 Replies
eWish
Expert 512MB
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
Jun 26 '08 #2
100+
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 ,
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. <?php
  3. echo "IP Address Is : ";
  4. echo $_SERVER['HTTP_X_FORWARDED_FOR']; // Show IP
  5.  
  6. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  7.  
  8. echo " Host Name : ";
  9. echo gethostbyaddr($ip);
  10. $mac = returnMacAddress();
  11. function returnMacAddress() {
  12.  
  13. // Get the arp executable path
  14. $location = `which arp`;
  15. // Execute the arp command and store the output in $arpTable
  16. $arpTable = `$location`;
  17. // Split the output so every line is an entry of the $arpSplitted array
  18. $arpSplitted = split("\n",$arpTable);
  19. // Get the remote ip address (the ip address of the client, the browser)
  20.  
  21. $remoteIp = $ip;
  22. foreach ($arpSplitted as $value) {
  23. // Split every arp line, this is done in case the format of the arp
  24. // command output is a bit different than expected
  25. $valueSplitted = split(" ",$value);
  26. foreach ($valueSplitted as $spLine) {
  27. if (preg_match("/$remoteIp/",$spLine)) {
  28. $ipFound = true;
  29. }
  30. // The ip address has been found, now rescan all the string
  31. // to get the mac address
  32. if ($ipFound) {
  33. // Rescan all the string, in case the mac address, in the string
  34. // returned by arp, comes before the ip address
  35. // (you know, Murphy's laws)
  36. reset($valueSplitted);
  37. foreach ($valueSplitted as $spLine) {
  38. if (preg_match("/[0-9a-f][0-9a-f][:-]".
  39. "[0-9a-f][0-9a-f][:-]".
  40. "[0-9a-f][0-9a-f][:-]".
  41. "[0-9a-f][0-9a-f][:-]".
  42. "[0-9a-f][0-9a-f][:-]".
  43. "[0-9a-f][0-9a-f]/i",$spLine)) {
  44. return $spLine;
  45. }
  46. }
  47. }
  48. $ipFound = false;
  49. }
  50. }
  51. return false;
  52. }
  53.  
  54.  
Jun 26 '08 #3
eWish
Expert 512MB
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
Jun 26 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Andres Baravalle | last post: by
9 posts views Thread by Jeff | last post: by
2 posts views Thread by ajd335 | last post: by
1 post views Thread by Ivan Ven Osdel | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.