【php】GET POST 请求类 伪装IP

小涛 14 天前 55

代码

/**
 * 全局操作
 * @package XIAOTAO (www.xiaotaowl.com)
 */

class curlSet
{

    public function __construct($proxy = '', $proxyuserpwd = ''){
        $this->proxy = $proxy;
        $this->proxyuserpwd = $proxyuserpwd;
        $this->cny = 6.65;
    }

    // 外网访问 $url, $type, $data = '', $head = [], $proxy = '', $proxyuserpwd = ''
    public function wget($url, $type = 0, $data = '', $head = [], $pro = FALSE){
        $curl = curl_init();

        curl_setopt($curl, CURLOPT_URL, $url);//地址

        if($type == 1){
            curl_setopt($curl, CURLOPT_POST, 1); // post传输
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // post数据,字符串
        }

        curl_setopt($curl,CURLOPT_HTTPHEADER, $head); // 协议头,数组

        if ($pro == true) {
            curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //使用http代理模式 CURLPROXY_SOCKS5 CURLPROXY_HTTP 默认
            curl_setopt($curl, CURLOPT_PROXY, $this->proxy); // 代理访问 服务器地址端口
            curl_setopt($curl, CURLOPT_PROXYUSERPWD, $this->proxyuserpwd); // 代理访问 用户:密码

        }

        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 2000); // 时间 毫秒 0无限等待
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // 证书
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); // 证书SSL加密
        curl_setopt($curl, CURLOPT_HEADER, true);// 返回协议头
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 转为字符串输出
        $output = curl_exec($curl);

        $size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
        $header = substr($output, 0, $size);
        $body = substr($output, $size);
        curl_close($curl);
        //var_dump($body);
        return [0 => $header, 1 => mb_convert_encoding($body, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5')];
    }
    // 伪装IP
    public function sip(){
        $arr_1 = array("218","218","66","66","218","218","60","60","202","204","66","66","66","59","61","60","222","221","66","59","60","60","66","218","218","62","63","64","66","66","122","211");
        $randarr= mt_rand(0,count($arr_1));
        $ip1id = $arr_1[$randarr];
        $ip2id=  round(rand(600000,  2550000)  /  10000);
        $ip3id=  round(rand(600000,  2550000)  /  10000);
        $ip4id=  round(rand(600000,  2550000)  /  10000);
        $reip = $ip1id . "." . $ip2id . "." . $ip3id . "." . $ip4id;

        return  ['X-Forwarded-For: '.$reip, 'X-Remote-IP: '.$reip, 'X-Remote-Ip: '.$reip, 'X-Client-Ip:'.$reip, 'X-Client-IP:'.$reip, 'Cookie: os=A; appid=com.gamevil.idlecs.android.google.global.normal; device_model=HD1910; os_version=5.1.1;  game_language=zh-hans; language=zh-hans; country=HK; sdk_version=4.15.4.1; hive_theme=hivelight', 'X-Requested-With: XMLHttpRequest'];
    }

    // 邮箱收件箱
    public function get_mails($user){
        $arr = json_decode($this->wget('http://xxxxx', 1, 'p=1&username='.urlencode($user), $this->sip(),true)[1], true);
        // var_dump($arr);
        return $arr;
    }

}

实例

$tcu = new curlSet();
$ret = $tcu->get_mails('');
点赞 0