The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Changing IP of multiple sites through Shell

Discussion in 'General Discussion' started by ck@phptalk, Aug 31, 2006.

  1. ck@phptalk

    ck@phptalk Active Member

    Joined:
    Nov 6, 2003
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Earth
    Hi,

    Basically

    http://******:2087/scripts2/dochangeip?user=USERNAME&oldip=OLDIP&customip=NEWIP

    changes a single sites IP address.



    I'm looking for changing IP address of sites through shell, and if you let me know how to do, i would appreciate.

    Sample: /scripts/changeip.sh?user=USERNAME&oldip=OLDIP&customip=NEWIP


    PS: There are /scripts/changeip.sh, /scripts/changeip2.sh and /scripts/changeip3.sh scripts but i'm unsure whether these work.


    Best wishes,
    CK
     
  2. yaax

    yaax Well-Known Member

    Joined:
    Jun 15, 2003
    Messages:
    67
    Likes Received:
    0
    Trophy Points:
    6
    There is no way do it with existing cpanel scripts, so when I was need to move one big reseller with many sites to his dedicated ip I wrote such script myself using CPanel API.

    You need to save this script like any name for example script.cgi, update there your root hash key and then execute it from root with next parameters:
    ./script.cgi reseller oldip newip

    So this script will list all reseller sites of reseller with username 'reseller' and will change their 'oldip' to 'newip'

    PHP:
    #!/usr/bin/perl

    BEGIN {

            
    push (@INC,"/usr/local/cpanel");

    }
    use 
    Cpanel::Accounting;

    my($whm) = Cpanel::Accounting->new;

    $whm->{host} = "localhost";

    $whm->{user} = "root";

    $whm->{accesshash} = '';

    $whm->{usessl} = 1;

    my($self,$user) = @_;
       
    my($response);
       
       
    my($par);
       
    $par="/scripts2/listaccts?searchtype=owner&search=$ARGV[0]&acctp=999&nohtml=1";
       print 
    "$par\n";
       
    my (@PAGE) = $whm->whmreq($par);

       if (
    $whm->{errorne "") {
            print 
    "There was an error while processing your request:
            Cpanel::Accounting returned [
    $whm->{error}]\n";
            exit;
       }

       foreach 
    $_ (@PAGE) {
            
    s/\n//g;
           
    $response .= $_ "\n";
       }

       print 
    $response;

       
    my(%ACCTS);

       foreach 
    $_ (@PAGE) {
          
    s/\n//g;
          
    my($acct,$contents) = split(/=/, $_);
          
    my(@CONTENTS)=split(/\,/,$contents);
          @{
    $ACCTS{$acct}} = @CONTENTS;
       }

       foreach 
    $acct (sort keys %ACCTS) {

            @
    ACCTCT = @{$ACCTS{$acct}};

            print 
    "$acct @ACCTCT\n";
            print 
    "changing ip for account $acct from $ARGV[1] to $ARGV[2]...\n";

            
    my($response1);
            
    my (@PAGE1) = $whm->whmreq("/scripts2/dochangeip?user=$acct&oldip=$ARGV[1]&customip=$ARGV[2]");
       
            if (
    $whm->{errorne "") {
                    print 
    "There was an error while processing your request:
                    Cpanel::Accounting returned [
    $whm->{error}]\n";
                    
    #exit;
            
    }

            foreach 
    $_ (@PAGE1) {
                    
    s/\n//g;
                    
    $response1 .= $_ "\n";
            }

            print 
    $response1;
       }
     
    #2 yaax, Sep 3, 2006
    Last edited: Sep 3, 2006
Loading...

Share This Page