morrisonrox
morrisonrox

Reputation: 15

How i get the pc name, ip and mac addres with php or javascript?

I'm asking if there is a way to get the name, ip and mac of a pc with php or javacript?

I need this to configure a view in an application I developed. In this case, the user uses windows to access my application that is built with the PHP framework, codeignter, and obviously I use PHP to connect with the DB.

Why the name of the PC? Well ! the name of the pc in a network can be replaced with another pc with the same name. With the mac address can't. but its a way i cant get the name, ip and mac of a pc who acces to my aplication i want to know.

Upvotes: 0

Views: 2976

Answers (4)

Soteris 92
Soteris 92

Reputation: 121

To get the real IP address you can use this code

<?php
//whether ip is from share internet
if (!empty($_SERVER['HTTP_CLIENT_IP']))   
  {
    $ip_address = $_SERVER['HTTP_CLIENT_IP'];
  }
//whether ip is from proxy
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))  
  {
    $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
  }
//whether ip is from remote address
else
  {
    $ip_address = $_SERVER['REMOTE_ADDR'];
  }
echo $ip_address;
?>

Upvotes: 0

Michael Thompson
Michael Thompson

Reputation: 551

Using PHP, you can't get information about the computer specifically, unless it has been input into a form or something like that.

However, if you go to this question, you will find how to learn the name using Javascript.

How can I read the client's machine/computer name from the browser?

Upvotes: 0

Zerium
Zerium

Reputation: 17333

Impossible with just PHP, JavaScript, and nothing else.

You can get the IP address though, with $_SERVER['REMOTE_ADDR']. Note that if the user uses some kind of IP-hiding software like Hide My IP or such, this won't work either.

For the PC Name and Mac address, as Brad has mentioned, you need a client-side plugin, with another programming language, most likely Java or Flash.

Upvotes: 1

Brad
Brad

Reputation: 163272

Getting the MAC address isn't possible without some browser plugin client-side.

Also, you should know that it is very easy to change your MAC address. Besides, not everyone even has one. Ethernet is not a prerequisite for internet access.

You can get the remote address out of $_SERVER data in PHP, but it isn't always the real client IP, in cases of proxying or NAT.

Upvotes: 1

Related Questions