在php中更改ip地址
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在php中更改ip地址相关的知识,希望对你有一定的参考价值。
有没有办法在php中更改我的IP地址?任何api或一些图书馆?就像ZENMATE,Hotspot shield或IP VANISH一样?任何人都可以帮助我这件事是否可行?我得到这个代码形式谷歌搜索但这不帮助我,我也不知道它是如何工作的。任何来自你的帮助将不胜感激!
function routerDoConnect( $post )
{
$ip = "192.118.1.2";
$path = "/st_pptp.cgi";
$cleanPost = array();
$headers = "POST {$path} HTTP/1.1
";
$headers .= "Host: {$ip}
";
$headers .= "User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.11) Gecko/
2009060214 Firefox/3.0.11
";
$headers .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
";
$headers .= "Accept-Language: en-us,en;q=0.5
";
$headers .= "Accept-Encoding: gzip,deflate
";
$headers .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
";
$headers .= "Referer: http://192.168.1.1/RST_st_pptp.htm
";
$headers .= "Authorization: Basic " . base64_encode( "admin:secret" ) . "
";
$headers .= "Content-Type: application/x-www-form-urlencoded
";
foreach ( $post as $k => $v )
{
if ( is_array( $v ) )
{
$v = implode( "", $v );
}
$k = urlencode( $k );
$v = stripslashes( $v );
$v = urlencode( $v );
$cleanPost[] = "{$k}={$v}";
}
$postHeader = implode( "&", $cleanPost ) . "
";
$headers .= "Content-Length: " . ( strlen( $postHeader ) - 2 ). "
";
$headers .= $postHeader;
//echo nl2br( $headers );die();
$open = fsockopen( $ip, 80, $errno, $errstr, 60 );
if ( ! $open )
{echo( 'There was a problem connecting to the source.' );
die();
}
fputs( $open, $headers );
fgets( $open, 4096 );
fclose( $open );
}
echo "Disconnecting from ISP...";
routerDoConnect( array( 'disconnect' => "Disconnect" ) );
echo " Disconnected.<br />";
echo "Establishing new connection to ISP...";
routerDoConnect( array( 'connect' => " Connect " ) );
echo " Connected.<br /><br />Please allow 5 - 10 seconds for network to initiate.";
答案
试试这个(如果我理解正确的话)
function curlbrowse($url,$proxy_ip,$proxy_port,$loginpassw)
{
$loginpassw = 'username:password';
$proxy_ip = 'proxy ip';
$proxy_port = 'proxy port';
$url = 'http://www.domain.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
以上是关于在php中更改ip地址的主要内容,如果未能解决你的问题,请参考以下文章
php 在Yoast SEO中更改或删除OpenGraph输出的代码片段。此代码中有多个代码段。