Solved

Finding out what network I'm connected to

Posted on 2014-10-06
14
166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

717 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