473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Seeking VB.Net Proxy examples

Jim
I have seen http://www.vbdotnetheaven.com/Code/Aug2003/2146.asp - but it
does not work.

I need a working example....if anyone has seen one.

Jim
Jan 21 '06 #1
4 10804
Sorry for my ignorance, but what does a proxy server do exactly? I am not
familiar with the term "Proxy". Thanks for any info or links that you can
share.
--
Dennis in Houston
"Jim" wrote:
I have seen http://www.vbdotnetheaven.com/Code/Aug2003/2146.asp - but it
does not work.

I need a working example....if anyone has seen one.

Jim

Jan 21 '06 #2
Jim

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
Sorry for my ignorance, but what does a proxy server do exactly? I am
not
familiar with the term "Proxy". Thanks for any info or links that you can
share.


A proxy server makes requests on behalf of another machine (PC). Proxy
servers are mostly used for HTTP traffic, but can be used for any traffic
that needs a "go-between" for 2 PCs (like the servers that relay IM
conversations between PCs).

When a proxy is used for HTTP traffic, you must point your browser to the
proxy instead of to your cable modem, router or direct internet connection.
The proxy becomes the target of your HTTP requests. The proxy then connects
to the network (or internet) on your behalf, retrieves your requested
page/resource and passes it along to you.

Proxies can be used to filter out ads, pop-ups, viruses, adult content,
objectionable websites, allow anonymous web surfing (see www.anonymizer.com
for an example of this), etc.. They can also be used to track employee web
usage (a big brother kind of thing that I, personally, oppose).

For a better explanation, see http://en.wikipedia.org/wiki/Proxy_server .

Hope this helps.

Jim
Jan 21 '06 #3
Jim
I have found an example of VB.Net console proxy, and have fixed a couple of
errors. But, it does not seem to pass through pictures and throws an error
that says "An existing connection was forcibly closed by the remote host".

The goal is to be able to filter the content on the way to the browser. Any
help you could give with this project would be appreciated.

The VB.Net 2005 code is as follows......
Imports System '
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.IO
Imports System.Threading

Namespace WebProxy2

Class WebProxy2
Private clientSocket As Socket
Private read() As [Byte] = New Byte(1024) {}
Private Buffer As [Byte]() = Nothing
Private ASCII As Encoding = Encoding.ASCII
Private HTTP_VERSION As String = "HTTP/1.0"
Private CRLF As String = ControlChars.Cr + ControlChars.Lf
Private RecvBytes(4096) As [Byte]
Public Sub New(ByVal socket As Socket)
Me.clientSocket = socket
End Sub 'New

Public Sub run()
Dim clientmessage As [String] = " "
Dim sURL As [String] = " "
Dim bytes As Integer = readmessage(read, clientSocket,
clientmessage)
If bytes = 0 Then
Return
End If
Dim index1 As Integer = clientmessage.IndexOf(" "c)
Dim index2 As Integer = clientmessage.IndexOf(" "c, index1 + 1)
If index1 = -1 Or index2 = -1 Then
Throw New IOException()
End If
Console.WriteLine("Connecting to Site: {0}",
clientmessage.Substring(index1 + 1, index2 - index1))
Console.WriteLine("Connection from {0}",
clientSocket.RemoteEndPoint)

Dim part1 As String = clientmessage.Substring(index1 + 1,
index2 - index1)
Dim index3 As Integer = part1.IndexOf("/"c, index1 + 8)
Dim index4 As Integer = part1.IndexOf(" "c, index1 + 8)
Dim index5 As Integer = index4 - index3
sURL = part1.Substring(index1 + 4, part1.Length - index5 - 8)

Try
Dim IPHost As IPHostEntry = Dns.Resolve(sURL)
Console.WriteLine("Request resolved: ", IPHost.HostName)
Dim aliases As String() = IPHost.Aliases
Dim address As IPAddress() = IPHost.AddressList
Console.WriteLine(address(0))
Dim sEndpoint As New IPEndPoint(address(0), 80)
Dim IPsocket As New Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp)
IPsocket.Connect(sEndpoint)
If IPsocket.Connected Then
Console.WriteLine("Socket connect OK")
End If
Dim [GET] As String = clientmessage
Dim ByteGet As [Byte]() = ASCII.GetBytes([GET])
IPsocket.Send(ByteGet, ByteGet.Length, 0)
Dim rBytes As Int32 = IPsocket.Receive(RecvBytes,
RecvBytes.Length, 0)
Console.WriteLine("Recieved {0}", +rBytes)
'Buffer = RecvBytes;
Dim strRetPage As [String] = Nothing
strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0,
rBytes)
While rBytes > 0
rBytes = IPsocket.Receive(RecvBytes, RecvBytes.Length,
0)
strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0,
rBytes)
End While
IPsocket.Shutdown(SocketShutdown.Both)
IPsocket.Close()
sendmessage(clientSocket, strRetPage)
Catch exc2 As Exception
Console.WriteLine(exc2.ToString())
End Try
End Sub 'run

Private Function readmessage(ByVal ByteArray() As Byte, ByRef s As
Socket, ByRef clientmessage As [String]) As Integer
Dim bytes As Integer = s.Receive(ByteArray, 1024, 0)
Dim messagefromclient As String =
Encoding.ASCII.GetString(ByteArray)
clientmessage = CType(messagefromclient, [String])
Return bytes
End Function 'readmessage
Private Sub sendmessage(ByVal s As Socket, ByVal message As String)
Buffer = New [Byte](message.Length + 1) {}
Dim length As Integer = ASCII.GetBytes(message, 0,
message.Length, Buffer, 0)
s.Send(Buffer, length, 0)
End Sub 'sendmessage

'Entry point which delegates to C-style main Private Function
Public Overloads Shared Sub Main()
Main2(System.Environment.GetCommandLineArgs())
End Sub
Overloads Shared Sub Main2(ByVal args() As String)
Const port As Integer = 8889

'must set up local byte array for address type
Dim myIP(3) As Byte
myIP(0) = 127
myIP(1) = 0
myIP(2) = 0
myIP(3) = 1
Dim myLocalAddress As New System.Net.IPAddress(myIP)

'use byte array to open a listner
Dim tcplistener1 As New TcpListener(myLocalAddress, port)
'TcpListener(port)

Console.WriteLine("Listening on port {0}", +port)
tcplistener1.Start()
While True
Dim socket As Socket = tcplistener1.AcceptSocket()
Dim webproxy As New WebProxy2(socket)
Dim thread As New Thread(New ThreadStart(AddressOf
webproxy.run))
thread.Start()
End While
End Sub 'Main
End Class 'WebProxy2
End Namespace 'WebProxy2

Jan 21 '06 #4
Jim, thanks a lot for taking the time to educate me on proxies. This was an
excellent description.
--
Dennis in Houston
"Jim" wrote:

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
Sorry for my ignorance, but what does a proxy server do exactly? I am
not
familiar with the term "Proxy". Thanks for any info or links that you can
share.


A proxy server makes requests on behalf of another machine (PC). Proxy
servers are mostly used for HTTP traffic, but can be used for any traffic
that needs a "go-between" for 2 PCs (like the servers that relay IM
conversations between PCs).

When a proxy is used for HTTP traffic, you must point your browser to the
proxy instead of to your cable modem, router or direct internet connection.
The proxy becomes the target of your HTTP requests. The proxy then connects
to the network (or internet) on your behalf, retrieves your requested
page/resource and passes it along to you.

Proxies can be used to filter out ads, pop-ups, viruses, adult content,
objectionable websites, allow anonymous web surfing (see www.anonymizer.com
for an example of this), etc.. They can also be used to track employee web
usage (a big brother kind of thing that I, personally, oppose).

For a better explanation, see http://en.wikipedia.org/wiki/Proxy_server .

Hope this helps.

Jim

Jan 22 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fuzzyman | last post by:
I am trying to write a small server program that will work on a *client* machine as a localhost server. It should then act as a proxy server but modify URLs fetched through it - so that the fetches...
24
by: Joseph Geretz | last post by:
Up to this point, our application has been using Windows File Sharing to transfer files to and from our application document repository. This approach does not lend itself toward a secure...
5
by: Phil Adams | last post by:
Hi Peeps, I am trying to do some custom programming for CRM, but alas i am only a classic asp programmer. Can someone help me by translating this into asp.net in VB instead of C#, i can then get...
10
by: Jim | last post by:
I have seen http://www.vbdotnetheaven.com/Code/Aug2003/2146.asp - but it does not work. I need a working example....if anyone has seen one. Jim
2
by: Andrew R | last post by:
All, I couldn't get my xml-rpc script to work via a corporate proxy. I noticed a few posts asking about this, and a very good helper script by jjk on starship. That script didn't work for me,...
7
by: Pro1712 | last post by:
Hello, I need to write a simple proxy server. What I want to do is to use HttpListener to get requests from the browser, add some proxy information and some other stuff and send the request to...
4
by: smerf | last post by:
I am really new to this .Net stuff, but I am wondering if you can help me with a webservice issue. I have 15 locations that need to access a webservice. The webservice accepts XML and returns...
3
by: George Vasiliou | last post by:
Hi to all, I have made up a small client / server application with WinSock (port 443) at VB6. I have install server in my Home, and client is running behind a proxy server. Client cannot...
2
by: =?Utf-8?B?TGFycnlLdXBlcm1hbg==?= | last post by:
Our WebDev team seems to have found a problem that exposes a bug in .NET 2.0. This problem can be shown when trying to access a WebService using SSL and through a proxy server after using the...
2
by: =?Utf-8?B?TGVuc3Rlcg==?= | last post by:
A C# (.NET 2) application which uses the System.Net.HttpWebRequest object to request a resource over HTTPS is failing following the installation of a new proxy server on our internal network with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.