How to obtain Server IP Address using Javascript

V

Vanitha

Hi All,

Is it possible to get the Server IP Address from Javascript

ie., when the user types "http://10.0.0.10/main.htm" in the web
browser, i need to retrive the value of the IP Address(10.0.0.10) from
my client side javascript.
 
M

McKirahan

Vanitha said:
Hi All,

Is it possible to get the Server IP Address from Javascript

ie., when the user types "http://10.0.0.10/main.htm" in the web
browser, i need to retrive the value of the IP Address(10.0.0.10) from
my client side javascript.

Look at:
location.host
or
location.hostname
 
M

Mandy

Are you looking for an IP that will always be in the URL? In other words, if they go to a qualified Domain name, you would not be
able to get the IP?

If this is the case, I would use Regular Expressions to return the first match of:
/[ps]:\/\/([^\/]*\.)$\/?

Not sure on the \/... you might also try:
/[ps]://([^/]*\.)$/?

This should return the following for the following strings:
http://123.123.123.123/here.htm Returns:123.123.123.123
https://mydomain.com/here.htm Returns:mydomain.com
http://this.is.my.domain.name Returns: this.is.my.domain.name

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top