I have one 16Mbit ADSL2+ and two 8MBit ADSL connections. I noticed that
no (windows) applications offer the option to use multiple Local ip's
to 'talk' to the web. What i was working on, was a small util to
provide some basics for using multiple 'online' ip's to comunicate with
computers on the internet, a file transfer for example, or maybe a
newsgroup program.
What i did, was select one of the ip's from this array:
Dim IPs() As System.Net.IPAddress =
Dns.GetHostEntry(Dns.GetHostName).AddressList
I then wanted to connect to a remote ipendpoint, send/recieve data, and
return the results (never got to processing the HTML, so it returns the
page for now).
Example:
Public Function GetExternalIP(ByVal IP As IPAddress) As String
If Not IP.AddressFamily =
System.Net.Sockets.AddressFamily.InterNetwork Then Throw New
Exception("IPv4 Only for now!")
Dim Server As String = "www.whatismyip.com"
Dim S As New System.Net.Sockets.Socket(IP.AddressFamily,
SocketType.Stream, ProtocolType.Tcp)
S.Bind(New System.Net.IPEndPoint(IP, 0))
S.Connect(Server, 80)
Dim Req As String = String.Format("GET / HTTP/1.1{0}Host:
{1}{0}Connection: Close{0}{0}", vbCrLf, Server)
Dim SendBuffer As [Byte]() =
System.Text.Encoding.ASCII.GetBytes(Req)
Dim ReceiveBuffer(255) As [Byte]
S.Send(SendBuffer, SendBuffer.Length, 0)
Dim BytesLeft As Int32
Dim page As String = ""
Do
BytesLeft = S.Receive(ReceiveBuffer,
ReceiveBuffer.Length, 0)
page &=
System.Text.Encoding.ASCII.GetString(ReceiveBuffer, 0, BytesLeft)
Loop While BytesLeft > 0
Return page
End Function
When i select the IP of my 16MBit (which is default for this PC),
everything works, when i use one of the other IP's, it hangs at
connect, and all the socket properties in the locals screen give
errors.
Any idea what i am doing wrong?
Nick.