I am afraid that it is not possible to directly obtain an IP address through Javascript. It does not appear in the window.location object.
Part of the reason is that subsequently access to address:port not semantically the same as access to hostname:port - they are technically different URLs.
If what you really are after is part of the host of the URL from which the current web file was downloaded, you need to:
window.location.hostname window.location.port
The latter may be empty if the default port is used, so you should also read:
window.location.protocol
and check if it has http: (i.e. port 80) or https: (port 443).
You can also use:
window.location.host
which will contain both hostname and port as colon-separated strings, with the same caution as above, that the :port section will be omitted if the content is accessed through the default port for the protocol.
source share