Solved

Finding out what network I'm connected to

Posted on 2014-10-06
14
157 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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
 
LVL 14

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 14

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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