0

How to pass IPAddress to webBrowser control

This is my code but i don't know how to pass ip-address to webBrowser control.

IPHostEntry host;
string localIP = "?";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (string line in File.ReadAllLines("proxy.txt"))
{
    IPAddress ip = IPAddress.Parse(line);
    if (ip.AddressFamily.ToString() == "InterNetwork")
    {
        localIP = ip.ToString();
        textBox1.Text = ip.ToString();

        // This code doesn't work, it's just a hypothetical example:
        webBrowser1.SourceIPAddress=ip; 

        webBrowser1.Navigate(textBox2.Text);
    }
}

this is how i want to pass ip-address to webBrowser control

//The code doesn't work, it's just a hypothetical example:
webBrowser1.SourceIPAddress = ip;
Kjartan
  • 18,591
  • 15
  • 71
  • 96
user1608298
  • 321
  • 2
  • 6
  • 8
  • Why? Calling navigate with an IP address *string* should work fine. – aquinas Aug 20 '12 at 13:16
  • Because i want to pass ip-address to webBrowser1.Navigare(""); which ip i am reading from "proxy.txt" – user1608298 Aug 20 '12 at 13:22
  • 1
    And `webBrowser1.Navigate` is not a blocking method. It will return before navigation completes. – L.B Aug 20 '12 at 13:23
  • Right, have you tried actually doing: webBrowser1.Navigate("74.125.226.197"); for example? It works fine. You don't have to actually pass an IP address *object*. – aquinas Aug 20 '12 at 13:24
  • i am trying to use ip from proxy.txt to load "www.google.com" like: "www.google.com" with "74.125.226.197" ip. – user1608298 Aug 20 '12 at 13:31
  • Why would you loop like that? textBox1.Text is only going to have the last value. And if it did load webBrowser1 would be on the last. And there is no property SourceIPAddress for WebBrowser. – paparazzo Aug 20 '12 at 14:01

2 Answers2

4

Just Write in your textbox http://74.125.236.211

or

textBox2.Text="http://74.125.236.211"
perilbrain
  • 7,961
  • 2
  • 27
  • 35
0

What you really want to do isn't clear to me but I'll take a wild guess, assuming you want the download the url in textBox2.Text using a proxy server and want to try proxies in file proxy.txt until one sucessfully works.

foreach (var proxy in File.ReadAllLines("proxy.txt"))
{
    try
    {
        using (var wc = new WebClient())
        {
            wc.Proxy = new WebProxy(proxy);
            string page wc.DownloadString(textBox2.Text);
            return page;
        }
    }
    catch { }
}
L.B
  • 114,136
  • 19
  • 178
  • 224
  • i am trying to use ip from proxy.txt to load "www.google.com" like: "www.google.com" with "74.125.226.197" ip. – user1608298 Aug 20 '12 at 15:51
  • @user1608298 There is no such thing "load a page with XXX ip". You can not change your own IP. Do you mean "using a proxy with ip .." ? – L.B Aug 20 '12 at 15:55