Detect network change

As a followup to:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21217514.html

What is the best method to determine I have changed networks?  Should I try pinging the Nameservers?  Look at something on my NIC interface?

Thanks
LVL 6
platinumbayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

natlozCommented:
When you are on a different network are you on a different domain?

If so maybe WMI will help out...here is a sample

Imports System
Imports System.Management

Public Class frmMain
    Inherits System.Windows.Forms.Form

    'Detect Computer info
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim search1 As New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem") <----- FOCUS ON THIS
        Dim search2 As New ManagementObjectSearcher("SELECT * FROM Win32_CDROMDrive")
        Dim search3 As New ManagementObjectSearcher("SELECT * FROM Win32_PointingDevice")
        Dim search4 As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
        Dim search5 As New ManagementObjectSearcher("SELECT * FROM Win32_SystemEnclosure")
        Dim search6 As New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
        Dim search7 As New ManagementObjectSearcher("SELECT * FROM Win32_Product")

        Dim moInfo As ManagementObject

        For Each moInfo In search1.Get()
            txtInfo.Text = ("Computer: " & moInfo("Name").ToString() & ControlChars.CrLf & _
            "User Name: " & moInfo("UserName").ToString() & ControlChars.CrLf & _
            "Domain: " & moInfo("Domain").ToString() & ControlChars.CrLf & _   <--------------------LOOK AT DOMAIN MAYBE?
            "Total RAM: " & moInfo("TotalPhysicalMemory").ToString() & ControlChars.CrLf & _
            "Processor Count: " & moInfo("NumberOfProcessors").ToString() & ControlChars.CrLf)
        Next moInfo

        For Each moInfo In search2.Get()
            txtInfo.Text = txtInfo.Text + ("CDRom: " & moInfo("Name").ToString() & ControlChars.CrLf)
        Next moInfo

        For Each moInfo In search3.Get()
            txtInfo.Text = txtInfo.Text + ("Mouse: " & moInfo("Name").ToString() & ControlChars.CrLf)
        Next moInfo

        For Each moInfo In search4.Get()
            txtInfo.Text = txtInfo.Text & _
            ("Processor Description: " & moInfo("Description").ToString() & ControlChars.CrLf & _
            "Processor Name: " & moInfo("Name").ToString() & ControlChars.CrLf & _
            "Max Clock Speed: " & moInfo("MaxClockSpeed").ToString() & ControlChars.CrLf)
        Next moInfo

        For Each moInfo In search5.Get()
            txtInfo.Text = txtInfo.Text & _
            ("Manufacturer: " & moInfo("Manufacturer").ToString() & ControlChars.CrLf & _
            "Serial Number: " & moInfo("SerialNumber").ToString() & ControlChars.CrLf)
        Next moInfo

        For Each moInfo In search6.Get()
            txtInfo.Text = txtInfo.Text & _
            ("Operating System: " & moInfo("Name").ToString() & ControlChars.CrLf)
        Next moInfo

        txtInfo.Text = txtInfo.Text + "--------------------" & ControlChars.CrLf

        For Each moInfo In search7.Get()
            txtInfo.Text = txtInfo.Text & ("Product Name: " & moInfo("Name").ToString() & ControlChars.CrLf)
        Next moInfo


    End Sub
End Class
0
RonaldBiemansCommented:
if you just want the local domainname just use

environment.UserDomainName
0
platinumbayAuthor Commented:
Actually, I am not on any domain.  My laptop is in workgroup mode.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

natlozCommented:
Ok....substitute

 For Each moInfo In search1.Get()
            txtInfo.Text = ("Computer: " & moInfo("Name").ToString() & ControlChars.CrLf & _
            "User Name: " & moInfo("UserName").ToString() & ControlChars.CrLf & _
            "Workgroup: " & moInfo("Workgroup").ToString() & ControlChars.CrLf & _   <--------------------LOOK AT Workgroup
            "Total RAM: " & moInfo("TotalPhysicalMemory").ToString() & ControlChars.CrLf & _
            "Processor Count: " & moInfo("NumberOfProcessors").ToString() & ControlChars.CrLf)
        Next moInfo

If you store the workgroup in a textfile you can see if it has changed perhaps.
0
natlozCommented:
This may be all that you need..........
-----------------------------------------------

Imports System
Imports System.Management

Public Class frmMain
    Inherits System.Windows.Forms.Form

    'Detect Computer info
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim search1 As New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem") <----- FOCUS ON THIS
        Dim moInfo As ManagementObject

        For Each moInfo In search1.Get()
            txtInfo.Text =  moInfo("Workgroup").ToString()        
       Next moInfo

    End Sub
End Class
0
platinumbayAuthor Commented:
But my workgroup doesn't change.  It is static in both places.  I use a dynamic IP both places, and just switch the forwarders in my DNS.  I need some way of detecting the change, and I think it will have to be an external entity, such as pinging for a specific computer, or whatnot.  Thoughts?
0
natlozCommented:
What happens if you don't switch the forwarders in your DNS...can you then test for a Database failure or something of that nature.?
0
platinumbayAuthor Commented:
If I don't switch the forwarders when I get to work, I don't get an IP from the network, and I'm pretty much isolated.  If I don't switch them when I get home, I can't get out on the Internet because I won't be pointing to my ISP's DNS for name resolution, though I do pick up an IP.

Maybe I will just try pinging a work NS, if nothing comes back, then I'll know I'm not at work.

In any case, I have the BAT files from the previous post, and that alone is wonderful.
0
armoghanCommented:
Hi platinumbay,
You can also check through WMI any change in Forwarder by checking this class or the start of your application
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dns/dns/microsoftdns_server.asp

Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.