?
Solved

Detect network change

Posted on 2004-11-23
10
Medium Priority
?
187 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:platinumbay
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 7

Expert Comment

by:natloz
ID: 12657656
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
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12657700
if you just want the local domainname just use

environment.UserDomainName
0
 
LVL 6

Author Comment

by:platinumbay
ID: 12658392
Actually, I am not on any domain.  My laptop is in workgroup mode.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 7

Expert Comment

by:natloz
ID: 12658759
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
 
LVL 7

Expert Comment

by:natloz
ID: 12658784
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
 
LVL 6

Author Comment

by:platinumbay
ID: 12659171
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
 
LVL 7

Expert Comment

by:natloz
ID: 12659293
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
 
LVL 6

Author Comment

by:platinumbay
ID: 12660375
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
 
LVL 18

Expert Comment

by:armoghan
ID: 12673035
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
 
LVL 18

Accepted Solution

by:
armoghan earned 2000 total points
ID: 12673076
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question