Can Vb.Net do this?

J

jim

I have a user that uses a built-in wireless ethernet card to connect to our
wireless router and surf the internet from behind our router and uses a
wireless Sprint card to connect to the internet when not in the office.

I need to be able to detect when he is connected from the office and when he
is connected via the Sprint card.

Monitoring the status of the Local Area Connection may not be the best
solution because he may use it to connect at hotspots outside the office and
I need to know specifically if he is connected at the office (AT&T/Bellsouth
DSL) or to another hotspot on the AT&T/Bellsouth DSL network.

Any ideas? Any sample code?

Thanks!
 
J

jim

Yeah...I know.....this is a CSharp group....but I could use your help too.
I can convert the CSharp code ( I think) if you know of any that can help me
do this.

Thanks for you help!
 
G

Guest

if i understand you correctly ,,

You need to know if a person is connected from your office to the internet
or at another place

this is pretty simple , just check if a known location at your intranet is
availlable
( for instance by pinging )


:) or am i thinking to simple
 
S

Smokey Grindle

that wouldn't tell if you are connected to two different types of
connections... that would just tell you if you had an internet connection or
could reach a server ;) but that could work in this instance for him, never
know.. in our office though we have pinging disabled internally.. and
external pings also.. so in our case ping wouldnt work but this isnt us :)
 
J

jim

That's a good idea. But, to keep from constantly pinging for the server, is
there a way to detect the disconnection and connection events of the Local
Area Network card?
 
A

AMDRIT

I have to ask, who/what needs to know the manner of connection and why?

If the who is the corporate office and the why is to monitor behavior, there
are a number of ways of determining the connection, mostly they are
infrastructure solutions. If your router or switches support logging, you
can read the logs and determine the connection.

If the who is an applicatoin and the why is to alter behavior or options,
then you can enumerate over the installed NIC's and determine if they are
active. You can accomplish this with unmanaged API calls
(planet-source-code.com, mvps.org/vbnet), with
system.net(NetworkInterface/Adapters), and from managed WMI . You can even
capture events when network configurations change.

Beyond that you can create a mixture of the two solutions. The query
portions (option 2) resides on the client as a service or some such and a
controller will live at the home office (Option 1/alternative - roll your
own monitor service.)
 
J

jim

There are 2 users that have 2 profiles in outlook 2003. They need 2 profiles
because the office DSL only allows emails to be sent via Bellsouth mail
servers and when on the road, their Sprint mobile wireless only allows
emails to be sent via Sprint servers. (Both ISPs say that they have these
restrictions to help stem the flow of spam.)

Since you can't have 2 mail server entries in a single profile, you need 2
profiles.

This can be a pain in the arse...as there is no way (that I have found) to
keep the 2 profiles in sync on a single PC. And, the few Outlook PC-to-PC
profile syncing apps that I have found don't sync everything (folders as
well as contacts, messages, etc.).

I found a way to change the outgoing email server automatically, but I have
to reliably detect where they are and make system changes automatically if
they change where they connect to the internet.

If I can detect that the Local Area Network connection has "connected", I
can then do the simple ping that is suggested here and make changes (or not)
depending on the ping's response. And, if I can detect the "connected"
event, I can avoid constant pinging and reserve system resources. (I just
hate wasting CPU cycles and such...)

If anyone knows of a better solution, I'm all ears.
 
J

jim

Cancel requests.....after 6 hours of searching, I got something that will
work (at least temporarily)....

Thanks for the posts though.

jim
 
S

Stephany Young

You seem miffed that it took you as long as 6 hours to find a solution to
your 'problem'.

I recommend that you learn to be patient because you will encounter
'problems' that will take you days if not weeks to fimd a solution for.
 
S

ShaneO

jim said:
Cancel requests.....after 6 hours of searching, I got something that will
work (at least temporarily)....

Thanks for the posts though.

jim

Jim, maybe it would be a good idea to let us know what you did to
overcome your problem, afterall, we can all learn from each other and
maybe save someone else spending 6 (or more) hours later!

There's probably lots of ways to overcome your problem, but I for one
would be interested to read, even a brief description, of what you
decided on.


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
J

jim

ShaneO said:
Jim, maybe it would be a good idea to let us know what you did to overcome
your problem, afterall, we can all learn from each other and maybe save
someone else spending 6 (or more) hours later!

There's probably lots of ways to overcome your problem, but I for one
would be interested to read, even a brief description, of what you decided
on.


ShaneO


I spoke too soon.

I didn't take into account that the Sprint server requires a login to send
mail and the Bellsouth servers don't. That means that to handle the problem
from an Outlook point of view I would have to muck around with VSTO and
God-only-knows what else.

I have another idea that just might work though. I'll let you know.

jim
 
R

rowe_newsgroups

That's a good idea. But, to keep from constantly pinging for the server, is
there a way to detect the disconnection and connection events of the Local
Area Network card?






That's a good idea. But, to keep from constantly pinging for the server, is
there a way to detect the disconnection and connection events of the Local
Area Network card?

Well I don't know how to listen to the (dis)connect events, but you
can check whether the network connection is enabled or disabled by
looking at the verb name for the connection. While the article was
written to enabled/disable the network connection you could modify it
to just return whether the connection is enabled or not:

http://www.codeproject.com/useritems/toggleNetworkConn.asp

Thanks,

Seth Rowe
 
J

jim

rowe_newsgroups said:
Well I don't know how to listen to the (dis)connect events, but you
can check whether the network connection is enabled or disabled by
looking at the verb name for the connection. While the article was
written to enabled/disable the network connection you could modify it
to just return whether the connection is enabled or not:

http://www.codeproject.com/useritems/toggleNetworkConn.asp

I used a handler for the NetworkChange.NetworkAddressChanged event, and it
seems to work just fine.

jim
 
J

jim

jim said:
I spoke too soon.

I didn't take into account that the Sprint server requires a login to send
mail and the Bellsouth servers don't. That means that to handle the
problem
from an Outlook point of view I would have to muck around with VSTO and
God-only-knows what else.

I have another idea that just might work though. I'll let you know.

OK....I needed a quick solution to this problem and I found a free one
instead of coding it myself (although that's what I'd rather do).

To solve the issue of being on 2 seperate networks (each of which requires
you to use their own mail server and only one of which requires a
username/password) I used Sleepwalker's Free SMTP Proxy
(http://thesleepwalker.com/software/). It's written in VB6 - but no source
code is available.

I placed it on the Bellsouth DSL office server and redirected Outlook's mail
server to it. This way, no matter what network they are actually on,
Bellsouth mail servers always see the emails coming from the office DSL.

I'd love to make an open source .Net version, and I have the beginnings of
some code that may be able to help, but I am unsure of how to create the
outgoing connections to Bellsouth, how to relay the data between the
sockets, and how to tell when the connections should be closed.

This code is from Network Programming in .Net and is for a multi-threaded
file transfer app. It may be a start for a multithreaded proxy server.

<CODE>
Imports System.Threading
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.IO

Public Class Form1

Private alSockets As ArrayList

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim IPHost As IPHostEntry
IPHost = Dns.GetHostEntry(Dns.GetHostName())
Label1.Text = "My IP address is " & IPHost.AddressList(0).ToString
alSockets = New ArrayList
Dim thdListener As New Thread(New ThreadStart(AddressOf
listenerThread))
thdListener.Start()
End Sub

Public Sub listenerThread()
Dim tcpListener As New TcpListener(IPAddress.Any, 80808)
Dim handlerSocket As Socket
Dim thdstHandler As ThreadStart
Dim thdHandler As Thread

tcpListener.Start()
Do
handlerSocket = tcpListener.AcceptSocket
If handlerSocket.Connected Then
lbConnections.Items.Add(handlerSocket.RemoteEndPoint.ToString
& " connected.")
SyncLock (Me)
alSockets.Add(handlerSocket)
End SyncLock
thdstHandler = New ThreadStart(AddressOf handlerthread)
thdHandler = New Thread(thdstHandler)
thdHandler.Start()
End If
Loop

End Sub


Public Sub handlerThread()
'This function finds the last used socket and then retrieves the
stream from this socket.
'An array is allocated to the same size as the stream, and once the
stream is fully recieved,
'its contents are copied into this array.

Dim handlerSocket As Socket
handlerSocket = (alSockets(alSockets.Count - 1))
Dim networkStream As NetworkStream = New
NetworkStream(handlerSocket)
Dim blockSize As Int16 = 1024
Dim thisRead As Int16
Dim dataByte(blockSize) As Byte

SyncLock Me
'only 1 process can access the same file at any given time
Dim myfileStream As Stream
myfileStream = File.OpenWrite("c:\upload.txt")

While (True)
thisRead = networkStream.Read(dataByte, 0, blockSize)
myfileStream.Write(dataByte, 0, dataByte.Length)
If thisRead = 0 Then Exit While
End While

myfileStream.Close()
End SyncLock
lbConnections.Items.Add("File Written")
handlerSocket = Nothing
End Sub

End Class
</CODE>

While this code seems to do a straight read, write the file and cut the
connection, I'd need to open a new TCP connection to the Bellsouth mail
servers, relay the incoming info to the mail servers and know when the
incoming connection had been terminated by Outlook to be able to destroy the
handlerThread.

Any pointers you could give would be appreciated as I am so busy that the
Sleepwalker SMTP Proxy will simply have to do for now.

In my travels looking for an answer I did find out how to get the external
IP address and the ISPs name. But, they are largely irrelevant if I could
just do this proxy thing.

Thanks for your help!

jim
 
J

jim

jim said:
OK....I needed a quick solution to this problem and I found a free one
instead of coding it myself (although that's what I'd rather do).

To solve the issue of being on 2 seperate networks (each of which requires
you to use their own mail server and only one of which requires a
username/password) I used Sleepwalker's Free SMTP Proxy
(http://thesleepwalker.com/software/). It's written in VB6 - but no
source code is available.

I placed it on the Bellsouth DSL office server and redirected Outlook's
mail server to it. This way, no matter what network they are actually on,
Bellsouth mail servers always see the emails coming from the office DSL.

I'd love to make an open source .Net version, and I have the beginnings of
some code that may be able to help, but I am unsure of how to create the
outgoing connections to Bellsouth, how to relay the data between the
sockets, and how to tell when the connections should be closed.

This code is from Network Programming in .Net and is for a multi-threaded
file transfer app. It may be a start for a multithreaded proxy server.

<CODE>
Imports System.Threading
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.IO

Public Class Form1

Private alSockets As ArrayList

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim IPHost As IPHostEntry
IPHost = Dns.GetHostEntry(Dns.GetHostName())
Label1.Text = "My IP address is " & IPHost.AddressList(0).ToString
alSockets = New ArrayList
Dim thdListener As New Thread(New ThreadStart(AddressOf
listenerThread))
thdListener.Start()
End Sub

Public Sub listenerThread()
Dim tcpListener As New TcpListener(IPAddress.Any, 80808)
Dim handlerSocket As Socket
Dim thdstHandler As ThreadStart
Dim thdHandler As Thread

tcpListener.Start()
Do
handlerSocket = tcpListener.AcceptSocket
If handlerSocket.Connected Then

lbConnections.Items.Add(handlerSocket.RemoteEndPoint.ToString & "
connected.")
SyncLock (Me)
alSockets.Add(handlerSocket)
End SyncLock
thdstHandler = New ThreadStart(AddressOf handlerthread)
thdHandler = New Thread(thdstHandler)
thdHandler.Start()
End If
Loop

End Sub


Public Sub handlerThread()
'This function finds the last used socket and then retrieves the
stream from this socket.
'An array is allocated to the same size as the stream, and once the
stream is fully recieved,
'its contents are copied into this array.

Dim handlerSocket As Socket
handlerSocket = (alSockets(alSockets.Count - 1))
Dim networkStream As NetworkStream = New
NetworkStream(handlerSocket)
Dim blockSize As Int16 = 1024
Dim thisRead As Int16
Dim dataByte(blockSize) As Byte

SyncLock Me
'only 1 process can access the same file at any given time
Dim myfileStream As Stream
myfileStream = File.OpenWrite("c:\upload.txt")

While (True)
thisRead = networkStream.Read(dataByte, 0, blockSize)
myfileStream.Write(dataByte, 0, dataByte.Length)
If thisRead = 0 Then Exit While
End While

myfileStream.Close()
End SyncLock
lbConnections.Items.Add("File Written")
handlerSocket = Nothing
End Sub

End Class
</CODE>

While this code seems to do a straight read, write the file and cut the
connection, I'd need to open a new TCP connection to the Bellsouth mail
servers, relay the incoming info to the mail servers and know when the
incoming connection had been terminated by Outlook to be able to destroy
the handlerThread.

(slight correction)
While this code seems to do a straight read, write the file and cut the
connection, I'd need to open a new TCP connection to the Bellsouth mail
servers, relay the incoming stream to the mail servers & relay the incoming
mail
server stream to the handlerThread's socket (thereby creating an SMTP
"tunnel" of sorts via the server) and know when the incoming connection had
been terminated by Outlook to be able to destroy the handlerThread.
 
A

AMDRIT

Another thing, if they are filtering port 25 traffic, then switch the port
they are sending SMTP on. If you have the ability to set up a VPN, even
better because Sprint and Bell South cannot peer into the tunnel. I guess I
just wouldn't settle for the vendor restricting my usage.
 
J

jim

I used another port and it seems fine.

AMDRIT said:
Another thing, if they are filtering port 25 traffic, then switch the port
they are sending SMTP on. If you have the ability to set up a VPN, even
better because Sprint and Bell South cannot peer into the tunnel. I guess
I just wouldn't settle for the vendor restricting my usage.
 
C

C-Services Holland b.v.

rowe_newsgroups schreef:
Well I don't know how to listen to the (dis)connect events, but you
can check whether the network connection is enabled or disabled by
looking at the verb name for the connection. While the article was
written to enabled/disable the network connection you could modify it
to just return whether the connection is enabled or not:

http://www.codeproject.com/useritems/toggleNetworkConn.asp

Thanks,

Seth Rowe

I guess that only works for English versions of Windows. If you want to
use that for a program that's going to be used in other countries just
checking if a certain text appears in the name will fail.
 
R

rowe_newsgroups

rowe_newsgroups schreef:


I guess that only works for English versions of Windows. If you want to
use that for a program that's going to be used in other countries just
checking if a certain text appears in the name will fail.

Unfortunately you're correct (it also fails if you rename a
connection) - but I don't know how else you could match a specific
connection.

Thanks,

Seth Rowe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top