How do I know what IPs my server have?

2020-04-18 09:15发布

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?

标签: php ip
2条回答
男人必须洒脱
2楼-- · 2020-04-18 09:40

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 }'
查看更多
Ridiculous、
3楼-- · 2020-04-18 09:43

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;
}
查看更多
登录 后发表回答