I need to know the MAC and the IP address of the connect clients, how can I do this in PHP?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
You can do this easily using openWRT. If yo use a captive portal you can mix php and openWRT and make a relation between the IP and the mac.
You can write a simple PHP code using:
Later, using openWRT you can go to
/tmp/dhcp.leases
, you will get something with the form:There, you have the mac, the IP address and the hostname.
For windows server I think u can use this:
under linux using iptables you can log to a file each request to web server with mac address and ip. from php lookup last item with ip address and get mac address.
As stated remember that the mac address is from last router on the trace.
Server IP
You can get the server IP address from
$_SERVER['SERVER_ADDR']
.Server MAC address
For the MAC address, you could parse the output of
netstat -ie
in Linux, oripconfig /all
in Windows.Client IP address
You can get the client IP from
$_SERVER['REMOTE_ADDR']
Client MAC address
The client MAC address will not be available to you except in one special circumstance: if the client is on the same ethernet segment as the server.
So, if you are building some kind of LAN based system and your clients are on the same ethernet segment, then you could get the MAC address by parsing the output of
arp -n
(linux) orarp -a
(windows).Edit: you ask in comments how to get the output of an external command - one way is to use backticks, e.g.
But what if the client isn't on a LAN?
Well, you're out of luck unless you can have the client volunteer that information and transmit via other means.
In windows, If the user is using your script locally, it will be very simple :
You can get MAC Address or Physical Address using this code
I used explode many time because shell_exec ("ipconfig/all") return complete detail of all network. so you have to split one by one. when you run this code then you will get
your MAC Address 00-##-##-CV-12 //this is fake address for show only.