473,385 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to get the server's IP Address and redirect the user to local web system? JS

Exequiel
288 256MB
So far this is my code on how to redirect the user to the local server.
Expand|Select|Wrap|Line Numbers
  1. function connectToServer() {
  2.    window.location="http://192.168.1.154/gcc";
  3. }
  4. window.onload = connectToServer;
  5.  
but what if the ip address of the server changed?
My idea now is that i need to get the list of all IPs in the network and check every IP if the "/gcc" exist ?
so it looks like this "http://scanned_IP/gcc"? if exist redirect to that "http://scanned_IP/gcc", else continue scanning. .

How to do that in javascript?
I'm using only html with javascript.

Any replies are appreciated. :D
Oct 18 '14 #1

✓ answered by Dormilich

IIRC you need to set a CORS header (would have to google what it is exactly).

note: some libraries make it easier to configure AJAX.

5 1746
Dormilich
8,658 Expert Mod 8TB
make an AJAX HEAD Request. if you get a 200 OK, the IP exists.
Oct 18 '14 #2
Exequiel
288 256MB
thank you for your response dormilich.
heres my javascript now using XMLHttpRequest or AJAX HEAD Request,
Expand|Select|Wrap|Line Numbers
  1. function connectToServer()
  2. {
  3.     var http = new XMLHttpRequest();
  4.     var url = "http://192.168.1.154/gcc";//the right servers IP.
  5.     http.open('HEAD', url);
  6.     http.onreadystatechange = function() 
  7.     {
  8.         if (this.readyState == this.DONE) 
  9.         {
  10.             //alert(this.responseText + " - "+ this.status);
  11.             if(this.status == 0 || this.status == 200)
  12.             {
  13.                 alert("Url Exist.");
  14.                 document.location.href = url;
  15.             }
  16.             else
  17.             {
  18.                 alert("Url Not Exist.");    
  19.             }
  20.         }
  21.     };
  22.     http.send();
  23. }
  24.  
  25. window.onload = connectToServer;
  26.  
  27.  
even if i put the valid and invalid ip address for the server the result for this.status is always 0, so it will redirect to that ip with /gcc like this "http://192.168.1.155/gcc" - invalid, "http://192.168.1.154/gcc" - valid, how can i get the right output or the call back after visiting the url if the /gcc exist on that IP?

I tried this in IE and the result is ok no problem in this browser, but on other browsers like chrome, mozilla, opera, and safari its not working to this browser. how can i fixed this?

thank you. :)
Oct 19 '14 #3
Dormilich
8,658 Expert Mod 8TB
even if i put the valid and invalid ip address for the server the result for this.status is always 0
ah, SOP (same origin policy) strikes. you could try to enable CORS (cross origin resource sharing) otherwise you need to route the request through your server (i.e. ask via AJAX your server to make this HEAD request).
Oct 19 '14 #4
Exequiel
288 256MB
but how can i enable CORS? i read about CORS but i don't know how to code it in javascript to enable it. . ?
Oct 20 '14 #5
Dormilich
8,658 Expert Mod 8TB
IIRC you need to set a CORS header (would have to google what it is exactly).

note: some libraries make it easier to configure AJAX.
Oct 20 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Kona | last post by:
Hello, My server is part of a W2K domain. What do you advice me as account to run my SQL*Server, service started with a domain user account or as local system ? I need advices from a security...
2
by: ABCL | last post by:
Hi All, Can any one tell me that what is the difference between Network Service, Local Service and Local System ACcount for window services ABCL
1
by: Andrés G. Aragoneses | last post by:
Hello. I have a Windows Service which I want to execute a file. The service is running under the local system account but when the file is executed it seems to be run with the profile of the...
14
by: Spitfire | last post by:
Hi All, I've this weird question about pointers. I would like to know how to return the address of a local variable, safely!! Isn't that a unrecommended procedure? Doesn't it have possibilities...
3
by: SugarDaddy | last post by:
Here's my problem. I have an NT service (really a .NET service) running as local system. I have a .NET form running on the user account. The form and the service communicate via an IPC Channel...
14
by: akuva | last post by:
How to read a file which is in our webspace from localsystem in php. please give me ideas or any code if anybody has it will be helpful
0
by: ckkwan | last post by:
Hi All, I am writing a Win Services running win2000 server which requires to connect to a Web Service provided by WebShpere. I can't load the certificate (even with WSE2 SP3) wihtout...
1
by: swethak | last post by:
hi, i used mail function in my local system.In that i didn't get any errors and mail didn't receive.And in my php.ini consists ; For Win32 only. SMTP = localhost smtp_port = 25 ; For...
6
NawazAhmed
by: NawazAhmed | last post by:
Hi, I was trying to get local system's username in my code behind. I tried every almost possible way. Here is the scenario: My project is web based and I don't have a login screen....I need to get...
3
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a asp.net app. When session is invalid, how to redirect user to the login page? I don't want to add the code to redirect user to the login page into every page. Thanks, -Billy
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.