473,396 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Fetching Host name and MAC address

123 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
2 3489
pbmods
5,821 Expert 4TB
Heya, AJD.

The hostname is available in your $_SERVER array.

You can get the MAC address on a Unix system via the `ifconfig` command (i.e., system('ifconfig');). Be prepared to do some parsing, though.
Jun 26 '08 #2
ajd335
123 100+
Heya, AJD.

The hostname is available in your $_SERVER array.

You can get the MAC address on a Unix system via the `ifconfig` command (i.e., system('ifconfig');). Be prepared to do some parsing, though.

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

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

Similar topics

0
by: Andres Baravalle | last post by:
Hi, I have a problem using a URL fetching algorithm (HTTP 1.0). To download an image, I used to use this algorithm: <?php Header("Content-type: image/gif"); $referer =...
9
by: Jeff | last post by:
Is there a way to echo back a case sensitive $HTTP_HOST in PHP? For example if I type HostName.domain.com in my browser I want to return it exactly as it appears in the location part of the browser...
0
by: C3 | last post by:
Hi everone. I'm trying to write a shell script that fetches a number of images from a map website (www.whereis.com.au). Basically, the page asks you for a street address and then queries the...
5
by: Patrick | last post by:
Hi all, In my SQL procedures in DB2 8.2, I current declare several cursors that return select statements with 10 columns in it. As a result, assigning host variables becomes a coding mess, as...
2
by: martin lanny | last post by:
Simple network scanner is a part of my dotnet solution. It pings ip addresses in a selected network range and gives me the response time for each computer it finds. Anyhow, I would need to...
3
by: ajd335 | last post by:
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...
1
by: Ivan Ven Osdel | last post by:
>----- Original Message ----- Here's a function I wrote for checking remote or local file existence. It works for me but admittedly I haven't tested many cases with it. Also its currently...
4
by: tokcy | last post by:
HI every one, i am using tooltip on click of link and i want like when that tooltip open then background window would be blure(). can anyone help me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.