|
-
Feb 6th, 2009, 04:23 AM
#1
Thread Starter
Hyperactive Member
Proxy with Web Browser
hi,
I want to use Proxy with web browser. I got Code which i found some where in vb forums. Here is Code.
Code:
Imports System.Net
Public Class form1
' The structure we use for the information
' to be interpreted correctly by API.
Public Structure Struct_INTERNET_PROXY_INFO
Public dwAccessType As Integer
Public proxy As IntPtr
Public proxyBypass As IntPtr
End Structure
' The Windows API function that allows us to manipulate
' IE settings programmatically.
Private Declare Auto Function InternetSetOption Lib "wininet.dll" _
(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, _
ByVal lpdwBufferLength As Integer) As Boolean
' The function we will be using to set the proxy settings.
Private Sub RefreshIESettings(ByVal strProxy As String)
Const INTERNET_OPTION_PROXY As Integer = 38
Const INTERNET_OPEN_TYPE_PROXY As Integer = 3
Dim struct_IPI As Struct_INTERNET_PROXY_INFO
' Filling in structure
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
struct_IPI.proxy = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(strProxy)
struct_IPI.proxyBypass = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi("local")
' Allocating memory
Dim intptrStruct As IntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
' Converting structure to IntPtr
System.Runtime.InteropServices.Marshal.StructureToPtr(struct_IPI, intptrStruct, True)
Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sr As New StreamReader("d:\p.txt")
Dim ar As New ArrayList
While sr.Peek <> -1
ar.Add(sr.ReadLine.ToString)
End While
Dim rn As New Random
Dim pr As Integer
pr = rn.Next(ar.Count)
RefreshIESettings(ar.Item(pr).ToString)
ListBox1.Items.Add(ar.Item(pr).ToString)
WebBrowser1.AllowNavigation = True
WebBrowser1.AllowWebBrowserDrop = True
WebBrowser1.ScriptErrorsSuppressed = True
System.Threading.Thread.Sleep(5000)
WebBrowser1.Navigate("http:\\www.whatismyip.com")
Its not Working for me.. Please Help me. Random Proxy is added correctly in Listbox. Please Help me I will Add Rep.
-
Feb 6th, 2009, 05:11 AM
#2
Re: Proxy with Web Browser
Below code does the job but needs restart of Internet Explorer every time you Enable or Disable the settings.
vb.net Code:
Imports Microsoft.Win32 Public Class Form1 Public Sub EnableProxy( _ ByVal proxyAddress As String, _ ByVal proxyPort As Integer, _ ByVal bypassLocal As Boolean _ ) Dim regKey As RegistryKey = Nothing Try regKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True) regKey.SetValue("ProxyEnable", True, RegistryValueKind.DWord) regKey.SetValue("ProxyServer", proxyAddress + ":" + proxyPort.ToString, RegistryValueKind.String) If bypassLocal Then regKey.SetValue("ProxyOverride", "<local>", RegistryValueKind.String) Else regKey.DeleteValue("ProxyOverride", False) End If Catch ex As Exception MessageBox.Show(ex.Message) Finally If regKey IsNot Nothing Then regKey.Close() End If MessageBox.Show("Done") End Try End Sub Public Sub DisableProxy() Dim regKey As RegistryKey = Nothing Try regKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True) regKey.SetValue("ProxyEnable", False, RegistryValueKind.DWord) Catch ex As Exception MessageBox.Show(ex.Message) Finally If regKey IsNot Nothing Then regKey.Close() End If MessageBox.Show("Done") End Try End Sub Private Sub Button1_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button1.Click EnableProxy("111.222.333.444", 80, False) End Sub Private Sub Button2_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button2.Click DisableProxy() End Sub End Class
-
Feb 6th, 2009, 05:19 AM
#3
Thread Starter
Hyperactive Member
Re: Proxy with Web Browser
 Originally Posted by Deepak Sakpal
Below code does the job but needs restart of Internet Explorer every time you Enable or Disable the settings.
vb.net Code:
Imports Microsoft.Win32 Public Class Form1 Public Sub EnableProxy( _ ByVal proxyAddress As String, _ ByVal proxyPort As Integer, _ ByVal bypassLocal As Boolean _ ) Dim regKey As RegistryKey = Nothing Try regKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True) regKey.SetValue("ProxyEnable", True, RegistryValueKind.DWord) regKey.SetValue("ProxyServer", proxyAddress + ":" + proxyPort.ToString, RegistryValueKind.String) If bypassLocal Then regKey.SetValue("ProxyOverride", "<local>", RegistryValueKind.String) Else regKey.DeleteValue("ProxyOverride", False) End If Catch ex As Exception MessageBox.Show(ex.Message) Finally If regKey IsNot Nothing Then regKey.Close() End If MessageBox.Show("Done") End Try End Sub Public Sub DisableProxy() Dim regKey As RegistryKey = Nothing Try regKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Internet Settings", True) regKey.SetValue("ProxyEnable", False, RegistryValueKind.DWord) Catch ex As Exception MessageBox.Show(ex.Message) Finally If regKey IsNot Nothing Then regKey.Close() End If MessageBox.Show("Done") End Try End Sub Private Sub Button1_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button1.Click EnableProxy("111.222.333.444", 80, False) End Sub Private Sub Button2_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button2.Click DisableProxy() End Sub End Class
I have nearly 100 Proxy's. I want to use random, proxy each time whenever new website loads. Then do i ned to call EnableProxy each and every time?
It is not Working for me.. is there any problem with my OS?
Last edited by yogesh12; Feb 6th, 2009 at 05:27 AM.
-
Feb 6th, 2009, 05:31 AM
#4
Re: Proxy with Web Browser
In my opinion it'd be a bad idea to set IE's proxy each time. That'd be something users would absolutely hate.
You could however do something like this, which wont affect the IE proxy settings:
VB.NET Code:
Private Sub NavigateWithProxy(ByVal url As String)
Dim request As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create(url), Net.HttpWebRequest)
Dim rand As New Random()
Dim reader As System.IO.StreamReader
request.Proxy = New System.Net.WebProxy(proxyList(rand.Next(0, proxyList.Length)))
reader = New System.IO.StreamReader(request.GetResponse().GetResponseStream())
WebBrowser1.DocumentText = reader.ReadToEnd()
reader.Close()
End Sub
Where 'proxyList' is the array or collection of proxy addresses.
-
Feb 6th, 2009, 05:36 AM
#5
Re: Proxy with Web Browser
 Originally Posted by yogesh12
I have nearly 100 Proxy's. I want to use random, proxy each time whenever new website loads. Then do i ned to call EnableProxy each and every time?
It is not Working for me.. is there any problem with my OS?
No, you don't need to call it every time when new website loads. If you set it once then it will be applicable for rest of the websites that you open on later on. But if you are going choose random proxy out 100 then restarting Internet Explorer is not good.
Need to find out some way by which changing proxy with code should take effect while Internet Explore is running. I was digging around SendMessageTimeout API but had no luck so far. Have a look at this article.
-
Feb 6th, 2009, 05:49 AM
#6
Thread Starter
Hyperactive Member
Re: Proxy with Web Browser
 Originally Posted by Deepak Sakpal
No, you don't need to call it every time when new website loads. If you set it once then it will be applicable for rest of the websites that you open on later on. But if you are going choose random proxy out 100 then restarting Internet Explorer is not good.
Need to find out some way by which changing proxy with code should take effect while Internet Explore is running. I was digging around SendMessageTimeout API but had no luck so far. Have a look at this article.
My IP is Not Changing. Proxy is not working.. Can u tell me some suggestions?
-
Feb 6th, 2009, 05:50 AM
#7
Thread Starter
Hyperactive Member
Re: Proxy with Web Browser
 Originally Posted by Atheist
In my opinion it'd be a bad idea to set IE's proxy each time. That'd be something users would absolutely hate.
You could however do something like this, which wont affect the IE proxy settings:
VB.NET Code:
Private Sub NavigateWithProxy(ByVal url As String)
Dim request As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create(url), Net.HttpWebRequest)
Dim rand As New Random()
Dim reader As System.IO.StreamReader
request.Proxy = New System.Net.WebProxy(proxyList(rand.Next(0, proxyList.Length)))
reader = New System.IO.StreamReader(request.GetResponse().GetResponseStream())
WebBrowser1.DocumentText = reader.ReadToEnd()
reader.Close()
End Sub
Where 'proxyList' is the array or collection of proxy addresses.
Proxy si not working... Can u tell me some suggestion. I ma Very much frustated
-
Feb 6th, 2009, 06:58 AM
#8
Re: Proxy with Web Browser
 Originally Posted by yogesh12
Proxy si not working... Can u tell me some suggestion. I ma Very much frustated 
Sounds like ur network settings problem. Admin might have done something to restrict proxy.
-
Feb 6th, 2009, 07:01 AM
#9
Thread Starter
Hyperactive Member
Re: Proxy with Web Browser
 Originally Posted by Deepak Sakpal
Sounds like ur network settings problem. Admin might have done something to restrict proxy.
Its my Home Computer. Nobody has control over it. I checked on other system too. all has same Result. They are showing my Systems IP.
-
Feb 6th, 2009, 07:36 AM
#10
Re: Proxy with Web Browser
 Originally Posted by yogesh12
Proxy si not working... Can u tell me some suggestion. I ma Very much frustated 
In what way isnt it working? I cant give you suggestions unless you give me more information.
-
Feb 6th, 2009, 07:43 AM
#11
Thread Starter
Hyperactive Member
Re: Proxy with Web Browser
 Originally Posted by Atheist
In what way isnt it working? I cant give you suggestions unless you give me more information.
It is showing my Real IP Address. Its not showing Proxy IP..
-
Feb 6th, 2009, 07:49 AM
#12
Re: Proxy with Web Browser
What is showing you your real IP Address?
-
Feb 6th, 2009, 08:05 AM
#13
Thread Starter
Hyperactive Member
Re: Proxy with Web Browser
 Originally Posted by Atheist
What is showing you your real IP Address?
After SEtting IP Address I called webbrowser.navigate, and went to www.whatismyip.com and it always shows up only my real ip.
-
Feb 6th, 2009, 08:06 AM
#14
Re: Proxy with Web Browser
Why are you calling WebBrowser.Navigate? Just use the subroutine i showed you above instead.
-
Feb 6th, 2009, 08:08 AM
#15
Re: Proxy with Web Browser
Nevermind I overlooked a major flaw in my idea. The WebBrowser will need to send subsequent requests for images etc...which makes it all alot harder.
-
Feb 6th, 2009, 08:09 AM
#16
Thread Starter
Hyperactive Member
Re: Proxy with Web Browser
 Originally Posted by Atheist
Why are you calling WebBrowser.Navigate? Just use the subroutine i showed you above instead.
Will that web page be visible in web browser? how web browser can navigate without firing navigate event? i am nob.. please don mind my questions..
-
Feb 6th, 2009, 08:13 AM
#17
Thread Starter
Hyperactive Member
Re: Proxy with Web Browser
 Originally Posted by Atheist
Nevermind I overlooked a major flaw in my idea. The WebBrowser will need to send subsequent requests for images etc...which makes it all alot harder.
I too Thought Same thing and asked.. While Posting u too posted it.. can u please give me that code?
-
Mar 5th, 2010, 10:28 PM
#18
New Member
Re: Proxy with Web Browser
 Originally Posted by yogesh12
hi,
I want to use Proxy with web browser. I got Code which i found some where in vb forums. Here is Code.
Code:
Imports System.Net
Public Class form1
' The structure we use for the information
' to be interpreted correctly by API.
Public Structure Struct_INTERNET_PROXY_INFO
Public dwAccessType As Integer
Public proxy As IntPtr
Public proxyBypass As IntPtr
End Structure
' The Windows API function that allows us to manipulate
' IE settings programmatically.
Private Declare Auto Function InternetSetOption Lib "wininet.dll" _
(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, _
ByVal lpdwBufferLength As Integer) As Boolean
' The function we will be using to set the proxy settings.
Private Sub RefreshIESettings(ByVal strProxy As String)
Const INTERNET_OPTION_PROXY As Integer = 38
Const INTERNET_OPEN_TYPE_PROXY As Integer = 3
Dim struct_IPI As Struct_INTERNET_PROXY_INFO
' Filling in structure
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
struct_IPI.proxy = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(strProxy)
struct_IPI.proxyBypass = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi("local")
' Allocating memory
Dim intptrStruct As IntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
' Converting structure to IntPtr
System.Runtime.InteropServices.Marshal.StructureToPtr(struct_IPI, intptrStruct, True)
Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sr As New StreamReader("d:\p.txt")
Dim ar As New ArrayList
While sr.Peek <> -1
ar.Add(sr.ReadLine.ToString)
End While
Dim rn As New Random
Dim pr As Integer
pr = rn.Next(ar.Count)
RefreshIESettings(ar.Item(pr).ToString)
ListBox1.Items.Add(ar.Item(pr).ToString)
WebBrowser1.AllowNavigation = True
WebBrowser1.AllowWebBrowserDrop = True
WebBrowser1.ScriptErrorsSuppressed = True
System.Threading.Thread.Sleep(5000)
WebBrowser1.Navigate("http:\\www.whatismyip.com")
Its not Working for me.. Please Help me. Random Proxy is added correctly in Listbox. Please Help me I will Add Rep.
How can I disable Proxy??
Please help me.
Thanks!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|