Solved

Finding out what network I'm connected to

Posted on 2014-10-06
14
145 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 82

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 82

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 82

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

705 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

15 Experts available now in Live!

Get 1:1 Help Now