CGI change server IP address ??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • skyy
    New Member
    • May 2007
    • 109

    CGI change server IP address ??

    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???
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    You need to print a meta refresh tag to redirect the browser. Search on google for "meta tag tutorial" or something similar.

    Comment

    • skyy
      New Member
      • May 2007
      • 109

      #3
      Originally posted by KevinADC
      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" >);

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        Originally posted by skyy
        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?

        Comment

        • skyy
          New Member
          • May 2007
          • 109

          #5
          Originally posted by KevinADC
          Did you print an http header first?
          Yes...

          print "Content-type: text/html\n\n";

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            hmm, I'm stumped. I don't know why it does not work.

            Comment

            • skyy
              New Member
              • May 2007
              • 109

              #7
              Originally posted by KevinADC
              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....

              Comment

              • KevinADC
                Recognized Expert Specialist
                • Jan 2007
                • 4092

                #8
                Maybe Miller or Paul will have some advice for you. I don't know what the problem might be.

                Comment

                • alcazar
                  New Member
                  • Jun 2007
                  • 10

                  #9
                  You could give it a try with the below.
                  Code:
                  #Redirect The Page
                  @redirect='<meta http-equiv="refresh" content="0;URL=http://192.168.1.149/feedback/thankyou.html">';
                  print @redirect;



                  Originally posted by skyy
                  Yes...

                  print "Content-type: text/html\n\n";

                  Comment

                  • miller
                    Recognized Expert Top Contributor
                    • Oct 2006
                    • 1086

                    #10
                    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

                    Comment

                    • skyy
                      New Member
                      • May 2007
                      • 109

                      #11
                      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..

                      Comment

                      Working...