Solved

Finding out what network I'm connected to

Posted on 2014-10-06
14
150 Views
Last Modified: 2014-10-16
I need to find out the name of the NETWORK that this computer is connected to. The NETWORK ... NOT

REPEAT

****NOT****

^^^^^^^^^^^^^ NOT NOT NOT NOT NOT NOT NOT ....


.... the domain name.


My PC has not joined the domain. As a result, when I use things like Environment.UserDomainName I get my PC's own name, and ActiveDirectory functions throw errors.

solutions preferably in VB.NET but C# is acceptable
0
Comment
Question by:WernerVonBraun
  • 8
  • 3
  • 2
  • +1
14 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40363306
Do you mean the Workgroup name?  That's the only name any of my networks have since I don't have ActiveDirectory at all.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40363313
0
 
LVL 4

Author Comment

by:WernerVonBraun
ID: 40363314
Nope.

Ok - move your mouse down to the notifications area and hover it over the network icon.

It'll pop up something like

nameofsomenetwork
internet access

unidentified network
no internet access


and so on. I want to read "nameofsomenetwork" and "unidentified network"
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40363324
Those would be wireless networks.  I forgot that they have names.  I don't have any wireless running at the moment.
0
 
LVL 4

Author Comment

by:WernerVonBraun
ID: 40363327
Yeah. Or LAN connections. :-)
0
 
LVL 4

Author Comment

by:WernerVonBraun
ID: 40363340
ugh - so .... I loop through all connections:

For Each oAd As System.Net.NetworkInformation.NetworkInterface In System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces

I could get IP properties:
Dim oIPInt As System.Net.NetworkInformation.IPInterfaceProperties = oAd.GetIPProperties()

But then what? That may give me DNS addresses or whatnot, but they're all IP addresses. How do I get "nameofsomenetwork" out of that - or ANY name of any machine corresponding to what GetIPProperties returns?
0
 
LVL 4

Author Comment

by:WernerVonBraun
ID: 40363341
Even if I could get the "Connection-specific DNS Suffix" as you'd get when you run IPCONFIG in a command prompt, I'd be happy
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:frankhelk
ID: 40363344
I don't have an example at hand, but I'll try to point the way (even while it is not very elegant):

Spawn "ipconfig.exe /all" as command line process with the Shell() command (or via a Process class object) and redirect the output into a file or a buffer string etc.

Spawning by the Process class would look like this:
Dim myProcess As Process = New Process()
        Dim StringBuffer As String
        Dim CMD_Encoding As Encoding
        Dim Sys_Encoding As Encoding
        Dim StdOut As String
        Dim Path As String = My.Application.Info.DirectoryPath
        Dim ExitCode As Boolean = False
        Dim ref As DateTime

        myProcess.EnableRaisingEvents = False
        myProcess.StartInfo.RedirectStandardOutput = True
        myProcess.StartInfo.RedirectStandardError = True
        myProcess.StartInfo.UseShellExecute = False
        myProcess.StartInfo.CreateNoWindow = True
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        myProcess.StartInfo.Arguments = "/all"
        myProcess.StartInfo.FileName = "ipconfig.exe"
        myProcess.Start()

Open in new window

(After execution, StandardOutput and StandardError contents could the be found in the repective properties of the myProcess object)

Parse the output line by line for the desired info.

When using Shell(), calling would be a bit more simple, but catching the output would be (a bit) more complicated.
0
 
LVL 4

Author Comment

by:WernerVonBraun
ID: 40363346
gawd that's ugly BUT .... if nothing more elegant is presented here the poinks will be yours.
0
 
LVL 13

Assisted Solution

by:frankhelk
frankhelk earned 150 total points
ID: 40363352
Thanks for the compliments ... ;-)

Please be aware that the example code is just quick-ripped out of some of my code and has not been tested - it's more of a concept. This explains why there are variables declared but not used (sorry ... forgot to rip them out and can't edit anymore). Maybe there are more subtle things I forgot to include ... but at least it's part of code that works well ...
0
 
LVL 4

Author Comment

by:WernerVonBraun
ID: 40363369
Don't worry about that - I'll clean it up all nice and pretty [grin]
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 350 total points
ID: 40363729
I think you are after the network profiles which can be found in registry at

HKLM\Software\Microsoft\Windows NT\CurrentVersion\NetworkList
0
 
LVL 4

Author Comment

by:WernerVonBraun
ID: 40364457
Ok CodeCruiser, I think you're on to something there. I'm especially interested in the key

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles

Between the ProfileName and the DateLastConnected I think I'll be able to get the information I need.
0
 
LVL 4

Author Closing Comment

by:WernerVonBraun
ID: 40384279
Thank you both!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now