I am required to change ip adress everytime this function gets executed I am trying this code below .But I am completly confused.How can I do this

function getData($domainName, $ext)
{
    $proxy = array(
        1 => array(
            '88.255.101.247',
            '8080'
        ),

        2 => array(
            '176.53.2.122',
            '8080'
        ),

        3 => array(
            '37.123.96.237',
            '8080'
        )

    );

    shuffle($proxy);

    $servers = array(
        "biz" => "whois.neulevel.biz",
        "com" => "whois.internic.net",
        "us" => "whois.nic.us",
        "info" => "whois.nic.info",
        "name" => "whois.nic.name",
        "net" => "whois.internic.net",
        "tv" => "whois.nic.tv",
        "ru" => "whois.ripn.net",
        "org" => "whois.pir.org",

        "com.tr" => "whois.nic.tr",
        "gen.tr" => "whois.nic.tr",
        "web.tr" => "whois.nic.tr",
        "k12.tr" => "whois.nic.tr",
        "org.tr" => "whois.nic.tr"
    );
    $serverName = trim($servers[$ext]);
    $fullName = $domainName . "." . $ext;

    $curl=curl_init();
    curl_setopt($curl, CURLOPT_URL, $serverName);
    curl_setopt($curl, CURLOPT_PORT, 43);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT, 5);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $fullName . "\r\n");
    curl_setopt($curl, CURLOPT_PROXY, $proxy[0][0]);
    curl_setopt($curl, CURLOPT_PROXYPORT, $proxy[0][1]);

    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    $result = curl_exec($curl);
    curl_close($curl);

    print_r($result);

  }

  $veri = getData( "google", "com");

  echo htmlspecialchars($veri);

So I see you have a list of DNS servers, but I'm not quite sure why. The web server should already have a way of resolving domain names to IP addresses. What you want to do instead for curl_setopt($curl, CURLOPT_URL, $serverName); is simply set $serverName to the IP address you're trying to connect to.

Also, you are setting the user agent to $_SERVER['HTTP_USER_AGENT']. Keep in mind that the user agent is a string that web browsers send to the web server to identify themselves. Therefore, a user agent won't exist if you're running this script via a cron job or a CLI script (e.g. it will only work if you're running this PHP script from a web browser).

Also, lines 49 and 50 say to use the values within the $proxy array corresponding to the element with index 0. But your $proxy array has indexes 1, 2, and 3, and does not have an index 0.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.