Reputation: 1325
It looks like javascript does not provide the ability to get the ip address.
Though we can get the ip address using server side scripting.
Is this done based on security?
Upvotes: 2
Views: 287
Reputation: 156524
Not to be obtuse but - because the language designers did not think it was necessary.
There is a huge amount of typically "essential" functionality which is missing from JavaScript (think about the filesystem, networking, I/O, multithreading, etc). This is because the JavaScript language was designed as a web-browser scripting language, not a general purpose programming language (although recent runtimes have filled the gaps).
It's not difficult to determine the client or server IP address (e.g. it would be trivial to write an "nslookup" AJAX service on your server) and there are likely not many security concerns in doing so.
Upvotes: 5
Reputation: 4118
Because IP address has meaning only in the context of a connection between a client and a server over Internet, while JavaScript is purely a client-side language, designed to work regardless of a connection or a host.
Upvotes: 4