user4951
user4951

Reputation: 33050

How do I know what IPs my server have?

I am using curl and I want to randomize the IP curl used with the IPs available for my server.

I need to know the IPs available for my server. Though I can hard code it, is there a PhP program for that?

Upvotes: 1

Views: 192

Answers (2)

Akram El Hamdaoui
Akram El Hamdaoui

Reputation: 133

if you are in centos, run this command using php exec() and it will show you all availables ip interfaces.

ifconfig | grep inet | awk -F 'addr:' '{ print $2} ' | awk -F ' ' '{ print $1 }'

Upvotes: 3

dotancohen
dotancohen

Reputation: 31471

If you need to know your server's external IP address, use this function:

function myIp()
{
    $url="simplesniff.com/ip";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
}

Upvotes: 0

Related Questions