Get Private IP

I would like to know whether we can get Private IP of a system using any of the PHP function ?

In theory, if you’re company has one, or a predictable set of external IPs, you could check the IP address and internally redirect them to the local one, so they could still visit through yourcompany.net.

If what Tarh has concluded is true and all machines that will be accessing this are on the same private network as the server, then if you can prevent the users from accessing your script over the web and strictly through the private network (user connects to http://10.10.0.1/path/to/script rather than http://yourcompany.net/path/to/script), then you can retrieve the users private ip address as its not leaving your network.

Why do you want to get the client’s private IP?

There is no reliable way. There is/was some client-side “hacks” to do it. If you are working with a corporate network, then you have more options.

If I understand you correctly, then these two statements are true:

  • All of your users are coming from within your organization
  • You want to restrict users to logging in from specific physical computers

The second one would imply to me that this might also be true:

  • You (or another department that you can work with) have access to modify files on the users’ computers in most, if not all, cases

If all three of these statements are true, then the ultimate solution for you is to forget about IP addresses and jump directly to client-side SSL certificates. You can generate unique client-side certificates for each user of the system and install the certificates on the computers that you wish to allow access. Then, when the user logs in, you can compare the client-side certificate to the one that you’re expecting. This performs the machine-based authentication that you’re looking for.

This blog post explains how to set up such a system. Note that this method is the most difficult setup to pursue (but also the most secure).

If you don’t have access to modify files on the users’ computers, then there isn’t much that you can do to perform reliable machine-based authentication. There are several methods that you could try (e.g. setting a cookie on the user machine that never expires and then checking for it before allowing authentication, or requiring a browser plugin that provides the HDD serial number to your website alone), but all of them are flimsy (e.g. deleting the cookie would require the user to call support to reset it, or disabling your custom plugin would break the mechanism).

It’s not possible to get a private IP address without being on that networks. That’s why they’re private.

What do you need the private IP address for anyways? Maybe you’re asking for the wrong thing.

If by private IP, you mean the IP address that the system uses with it’s router: only if you are running it on a localhost.

JavaScript has no access to IP addresses at all. In ordcer for JavaScript to get an IP address it needs to be given to JavaScript by some other language that does have access to IP addresses. The only one of those that can run in the browser is Java.

We have a HRM system which have attendance register, if we can get private IP, we can avoid the staffs logging from other systems.

The script runs in my remote server. So its not possible!

Anyway with JS and get it and passed ?
:rolleyes: