You are viewing our Forum Archives. To view or take place in current topics click here.
Vb Webbrowser Proxy changing
Posted:

Vb Webbrowser Proxy changingPosted:

Redo
  • 2 Million
Status: Offline
Joined: Feb 19, 201014Year Member
Posts: 3,605
Reputation Power: 153
Status: Offline
Joined: Feb 19, 201014Year Member
Posts: 3,605
Reputation Power: 153
Hi wondering if anyone here knows how to make the vb webbrowser change proxys per refresh, using the proxy/port from a imported list
#2. Posted:
Hacz
  • Summer 2018
Status: Offline
Joined: Mar 04, 201014Year Member
Posts: 2,891
Reputation Power: 150
Status: Offline
Joined: Mar 04, 201014Year Member
Posts: 2,891
Reputation Power: 150
This can be done with the WebProxy class, assuming you are using a HttpWebRequest. The code is written in C#, but I'm sure you can port it over to VB easily. Yes the code could probably be better and different in many ways, but this is a basic way to do it, and it should work for what you're trying to accomplish.


private void sendRequest(bool proxy)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://*snip*/requestdata.php");
    request.Timeout = 5000; //adjust timeout if needed on older/slower proxies
    if (proxy)
       request.Proxy = new WebProxy("40.114.213.245", 8080);
    request.UserAgent = "Test Request: " + (proxy ? "with proxy" : "no proxy");
    webBrowser1.DocumentStream = request.GetResponse().GetResponseStream();
}


With Proxy: [ Register or Signin to view external links. ]
Without: [ Register or Signin to view external links. ]

If you have a server to test it on, here is the PHP script as well

<?php
echo $_SERVER['REMOTE_ADDR'];
echo "<br>";
echo $_SERVER['HTTP_USER_AGENT'];
?>
#3. Posted:
Redo
  • 2 Million
Status: Offline
Joined: Feb 19, 201014Year Member
Posts: 3,605
Reputation Power: 153
Status: Offline
Joined: Feb 19, 201014Year Member
Posts: 3,605
Reputation Power: 153
Hacz wrote This can be done with the WebProxy class, assuming you are using a HttpWebRequest. The code is written in C#, but I'm sure you can port it over to VB easily. Yes the code could probably be better and different in many ways, but this is a basic way to do it, and it should work for what you're trying to accomplish.


private void sendRequest(bool proxy)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://*snip*/requestdata.php");
    request.Timeout = 5000; //adjust timeout if needed on older/slower proxies
    if (proxy)
       request.Proxy = new WebProxy("40.114.213.245", 8080);
    request.UserAgent = "Test Request: " + (proxy ? "with proxy" : "no proxy");
    webBrowser1.DocumentStream = request.GetResponse().GetResponseStream();
}


With Proxy: [ Register or Signin to view external links. ]
Without: [ Register or Signin to view external links. ]

If you have a server to test it on, here is the PHP script as well

<?php
echo $_SERVER['REMOTE_ADDR'];
echo "<br>";
echo $_SERVER['HTTP_USER_AGENT'];
?>


The code did work but i'm not quite sure on what you're trying to show me with the pictures is that a proxy tester you built to test if the webbrowser is actually using the proxy?
#4. Posted:
Hacz
  • TTG Addict
Status: Offline
Joined: Mar 04, 201014Year Member
Posts: 2,891
Reputation Power: 150
Status: Offline
Joined: Mar 04, 201014Year Member
Posts: 2,891
Reputation Power: 150
Redo wrote The code did work but i'm not quite sure on what you're trying to show me with the pictures is that a proxy tester you built to test if the webbrowser is actually using the proxy?

Precisely. Just showing you that the code works.
#5. Posted:
Redo
  • TTG Contender
Status: Offline
Joined: Feb 19, 201014Year Member
Posts: 3,605
Reputation Power: 153
Status: Offline
Joined: Feb 19, 201014Year Member
Posts: 3,605
Reputation Power: 153
Hacz wrote
Redo wrote The code did work but i'm not quite sure on what you're trying to show me with the pictures is that a proxy tester you built to test if the webbrowser is actually using the proxy?

Precisely. Just showing you that the code works.


so this code changes proxy per refresh in list? I have used the script you provided and gained 67 views on a youtube video so I assume it works.
#6. Posted:
Hacz
  • Christmas!
Status: Offline
Joined: Mar 04, 201014Year Member
Posts: 2,891
Reputation Power: 150
Status: Offline
Joined: Mar 04, 201014Year Member
Posts: 2,891
Reputation Power: 150
Redo wrote so this code changes proxy per refresh in list? I have used the script you provided and gained 67 views on a youtube video so I assume it works.


With some variations, yes. You can store your proxies in a list and have it pull a random one out of the list and make the request.

Ex: Let's say you want 120 views. You can make a loop for the 120 requests and every time the proxy is called to be set, have the proxy address/port be randomly selected out of the list with Random.

So the request code could be like so:

private void prepare()
{
  for(int i = 0; i < 120; i++)
     sendRequest(true); //false if you want your ip
}
private void sendRequest(bool proxy)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create ("http://*snip*/requestdata. php");
    request.Timeout = 5000; //adjust timeout if needed on older/slower proxies
    if (proxy)
    {
       int index = new Random().Next(0, proxies.Count());
       string[] selProxy = proxies[index].Split(':');
       request.Proxy = new WebProxy(selProxy[0]/*ip*/, int.Parse(selProxy[1])/*port*/);
    }
    request.UserAgent = "Test Request: " + (proxy ? "with proxy" : "no proxy");
    webBrowser1.DocumentStream = request.GetResponse().GetResponse Stream();
}


There are some changes to the code that could be made to make it cleaner, but that is a basic way of doing it.
#7. Posted:
Redo
  • TTG Contender
Status: Offline
Joined: Feb 19, 201014Year Member
Posts: 3,605
Reputation Power: 153
Status: Offline
Joined: Feb 19, 201014Year Member
Posts: 3,605
Reputation Power: 153
Hacz wrote
Redo wrote so this code changes proxy per refresh in list? I have used the script you provided and gained 67 views on a youtube video so I assume it works.


With some variations, yes. You can store your proxies in a list and have it pull a random one out of the list and make the request.

Ex: Let's say you want 120 views. You can make a loop for the 120 requests and every time the proxy is called to be set, have the proxy address/port be randomly selected out of the list with Random.

So the request code could be like so:

private void prepare()
{
  for(int i = 0; i < 120; i++)
     sendRequest(true); //false if you want your ip
}
private void sendRequest(bool proxy)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create ("http://*snip*/requestdata. php");
    request.Timeout = 5000; //adjust timeout if needed on older/slower proxies
    if (proxy)
    {
       int index = new Random().Next(0, proxies.Count());
       string[] selProxy = proxies[index].Split(':');
       request.Proxy = new WebProxy(selProxy[0]/*ip*/, int.Parse(selProxy[1])/*port*/);
    }
    request.UserAgent = "Test Request: " + (proxy ? "with proxy" : "no proxy");
    webBrowser1.DocumentStream = request.GetResponse().GetResponse Stream();
}


There are some changes to the code that could be made to make it cleaner, but that is a basic way of doing it.


Sorry for all the noobie questions but it says proxies doesn't exist in current content would i make a new void for proxies?
#8. Posted:
Hacz
  • Summer 2018
Status: Offline
Joined: Mar 04, 201014Year Member
Posts: 2,891
Reputation Power: 150
Status: Offline
Joined: Mar 04, 201014Year Member
Posts: 2,891
Reputation Power: 150
Redo wrote
Sorry for all the noobie questions but it says proxies doesn't exist in current content would i make a new void for proxies?


We all start somewhere! But you would make a new string array:

private string[] proxies;


And then populate it from the file when loading them with OpenFileDialog:

this.proxies = File.ReadAllLines(openFileDialog1.FileName);
#9. Posted:
Redo
  • 2 Million
Status: Offline
Joined: Feb 19, 201014Year Member
Posts: 3,605
Reputation Power: 153
Status: Offline
Joined: Feb 19, 201014Year Member
Posts: 3,605
Reputation Power: 153
Hacz wrote
Redo wrote
Sorry for all the noobie questions but it says proxies doesn't exist in current content would i make a new void for proxies?


We all start somewhere! But you would make a new string array:

private string[] proxies;


And then populate it from the file when loading them with OpenFileDialog:

this.proxies = File.ReadAllLines(openFileDialog1.FileName);


Thank you so much +repp for the help code is fully working
#10. Posted:
Hacz
  • V5 Launch
Status: Offline
Joined: Mar 04, 201014Year Member
Posts: 2,891
Reputation Power: 150
Status: Offline
Joined: Mar 04, 201014Year Member
Posts: 2,891
Reputation Power: 150
Redo wrote
Thank you so much +repp for the help code is fully working


No problem. Feel free to PM me with any problems/questions you have or if you need help with anything on the program.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.