我需要执行一个脚本来访问绑定到特定IP地址的网站。我使用BindIpEndPointDelegate类在C#中找到了一些东西。
var req = (HttpWebRequest)WebRequest.Create("http://google.com/");
req.ServicePoint.BindIPEndPointDelegate = BindTo;
using (req.GetResponse());
static IPEndPoint BindTo(ServicePoint servicepoint, IPEndPoint remoteendpoint, int retrycount)
{
IPAddress ip = IPAddress.Any; //This is where you specify the network adapter's address
int port = 0; //This in most cases should stay 0. This when 0 will bind to any port available.
return new IPEndPoint(ip, port);
}
我不知道如何将该类传递给powershell。
感谢您的帮助!
答案 0 :(得分:0)
尝试一下(未经测试),这是与#C#代码相同的PowerShell:
function Bind-IPEndPointCallback([System.Net.IPAddress]$ip,$port)
{
New-Object -TypeName System.Net.IPEndPoint $ip, $port
}
$request = [System.Net.HttpWebRequest]::Create("http://somewhere.com")
$request.ServicePoint.BindIPEndPointDelegate={ (Bind-IPEndPointCallback -ip 10.10.10.10 -port 80 ) }
$request.GetResponse()