2

I am trying to make a simple website with only HTML & JavaScript. I want to display the visitors IP address on the screen. I tried to search a lot and came to a conclusion that that is not possible through JavaScript and I would have to use some server side scripting language like PHP. However, I don't want to increase the overheads, how can I achieve this without server side programming?

  • You mean SSL = Server Side Language? – Ja͢ck Jun 13 '12 at 08:37
  • 7
    SSL typically means Secure Sockets Layer. Please don't use it to mean Server Side Language. – Quentin Jun 13 '12 at 08:37
  • possible duplicate of [Get Client IP using just Javascript?](http://stackoverflow.com/questions/391979/get-client-ip-using-just-javascript) – Manse Jun 13 '12 at 08:40
  • Your overhead will be increased by whatever the overhead is of any service you use to obtain the information. With javascript you need to obtain the information elsewhere because it is not possible within javascript itself. The best way to obtain the client's IP address is by some sort of server side processing. It can be done client side, but IMHO that is significantly more overhead than server side. Flash, ActiveX, and Java should be capable of obtaining the machine's IP address from the client side. You cannot get an accurate Public IP without server side intervention. – Steve Buzonas Jun 13 '12 at 16:58

3 Answers3

6

It's easy, just find a service that will return the IP to you via JSONP:

How to get client IP address using jQuery

Other resources:

Can I perform a DNS lookup (hostname to IP address) using client-side Javascript?

How to get client's IP address using javascript only?

Community
  • 1
  • 1
Ja͢ck
  • 161,074
  • 33
  • 239
  • 294
2

You can't. JavaScript has no access to any API that will give that information other than via an HTTP request.

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205
2

NO. Javascript, can't access IP Address. You need an API or a PHP/ASP/JSON File on your web Server. Try this service

<script src="http://www.codehelper.io/api/ips/?js"></script>
<script>
alert(codehelper_ip.IP);
</script>
Ken Le
  • 1,740
  • 2
  • 21
  • 33