469,360 Members | 1,799 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,360 developers. It's quick & easy.

CGI change server IP address ??

109 100+
Hi..

I am working on a CGI script to enable client to obtain the server ip address and then change to the IP address it prefer.

The server IP address can be obtain from the environment variable SERVER_ADDR

I am trying to change the IP address of the server with the following script:

#!/usr/bin/perl -w

use strict;

my $URL="http://192.168.28.130";
print "Status: 302 Moved\nLocation: $URL\n\n";

system("/sbin/ifconfig eth0 192.168.28.130");


I managed to change the IP address of the server. But the Re-driection of the web page doesnt not happen.

Any idea how to solve this???
Jun 29 '07 #1
10 6772
KevinADC
4,059 Expert 2GB
You need to print a meta refresh tag to redirect the browser. Search on google for "meta tag tutorial" or something similar.
Jun 29 '07 #2
skyy
109 100+
You need to print a meta refresh tag to redirect the browser. Search on google for "meta tag tutorial" or something similar.
Hi... that doesnt work. I tried already. Thanks...

print qq(<meta http-equiv="refresh" content="0; URL=http://192.168.28.135">);
Jun 29 '07 #3
KevinADC
4,059 Expert 2GB
Hi... that doesnt work. I tried already. Thanks...

print qq(<meta http-equiv="refresh" content="0; URL=http://192.168.28.135">);

Did you print an http header first?
Jun 29 '07 #4
skyy
109 100+
Did you print an http header first?
Yes...

print "Content-type: text/html\n\n";
Jun 29 '07 #5
KevinADC
4,059 Expert 2GB
hmm, I'm stumped. I don't know why it does not work.
Jun 29 '07 #6
skyy
109 100+
hmm, I'm stumped. I don't know why it does not work.
I am also figuring out what happpen...

when i remove the change IP command:

system("/sbin/ifconfig eth0 192.168.28.130");

the script works well with the redirection. But then i won't be able to change the server IP address....
Jun 29 '07 #7
KevinADC
4,059 Expert 2GB
Maybe Miller or Paul will have some advice for you. I don't know what the problem might be.
Jun 29 '07 #8
alcazar
10
You could give it a try with the below.
Expand|Select|Wrap|Line Numbers
  1. #Redirect The Page
  2. @redirect='<meta http-equiv="refresh" content="0;URL=http://192.168.1.149/feedback/thankyou.html">';
  3. print @redirect; 
  4.  



Yes...

print "Content-type: text/html\n\n";
Jun 29 '07 #9
miller
1,089 Expert 1GB
192.168.*.* is a private IP subnet. You are not going to be able to redirect an external user to an IP in that range. Their browser will instead look in their own private subnet.

Also, changing the IP address on a system level has no effect on the web. Using ifconfig will just brake things. Don't do that.

Finally, if you set it to a real IP address, the meta redirect should work. You can also use a redirect header if you're using mod_perl. Or if you want to rely on the JavaScript level, you can use a window.location assignment.

- Miller
Jun 29 '07 #10
skyy
109 100+
Hi Miller,

so is there any other way to change IP address?
Is there no way to do a auto redirect of web page?

Thanks..
Jul 2 '07 #11

Post your reply

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

Similar topics

4 posts views Thread by Richard Cornford | last post: by
9 posts views Thread by Seum-Lim Gan | last post: by
reply views Thread by S | last post: by
3 posts views Thread by roger beniot | last post: by
4 posts views Thread by andreas.w.h.k. :-\) | last post: by
4 posts views Thread by =?Utf-8?B?RGFuaWVs?= | last post: by
2 posts views Thread by =?Utf-8?B?YW1pdA==?= | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.