tempgp

Hi
Ok Im going a bit crazy but can some one help me to get Defauld Geteway and net mask I assume the only way to get it is to use WMI, and I have no expiriance in doing that :-(

So would really apreciate some help :-)
Thanks!

PS: Oh yes im running 2005, maybe there are some new easy ways




Re: Visual Basic Language Default Geteway and Subnet Mask how to get them into string?

Rabtok

Hi,


I am currently exploring WMI so I will have a crack at it. For your own investigation download the tool WMICodeCreator.EXE from the MSDN web site, load it, set the language to VB .Net and start selecting the WMI classes and parameters, it generates code for you to test and use.






Re: Visual Basic Language Default Geteway and Subnet Mask how to get them into string?

tempgp

I have WMI tool but it only generates the SELECT statement

:-(






Re: Visual Basic Language Default Geteway and Subnet Mask how to get them into string?

tempgp

Oh I got wrong tool,

he code creator gives me the code, but I can find Defult getway






Re: Visual Basic Language Default Geteway and Subnet Mask how to get them into string?

Rabtok

Just ran the tool and selected a few parameters ... Create a new console project and paste this in


Imports System
Imports System.Management
Imports System.Windows.Forms

Namespace WMISample

Public Class MyWMIQuery

Public Overloads Shared Function Main() As Integer

Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_NetworkAdapterConfiguration")

For Each queryObj As ManagementObject in searcher.Get()

Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_NetworkAdapterConfiguration instance")
Console.WriteLine("-----------------------------------")
Console.WriteLine("Caption: {0}", queryObj("Caption"))

If queryObj("DefaultIPGateway") Is Nothing Then
Console.WriteLine("DefaultIPGateway: {0}", queryObj("DefaultIPGateway"))
Else
Dim arrDefaultIPGateway As String()
arrDefaultIPGateway = queryObj("DefaultIPGateway")
For Each arrValue As String In arrDefaultIPGateway
Console.WriteLine("DefaultIPGateway: {0}", arrValue)
Next
End If
Console.WriteLine("Description: {0}", queryObj("Description"))

If queryObj("IPAddress") Is Nothing Then
Console.WriteLine("IPAddress: {0}", queryObj("IPAddress"))
Else
Dim arrIPAddress As String()
arrIPAddress = queryObj("IPAddress")
For Each arrValue As String In arrIPAddress
Console.WriteLine("IPAddress: {0}", arrValue)
Next
End If
Console.WriteLine("IPEnabled: {0}", queryObj("IPEnabled"))

If queryObj("IPSubnet") Is Nothing Then
Console.WriteLine("IPSubnet: {0}", queryObj("IPSubnet"))
Else
Dim arrIPSubnet As String()
arrIPSubnet = queryObj("IPSubnet")
For Each arrValue As String In arrIPSubnet
Console.WriteLine("IPSubnet: {0}", arrValue)
Next
End If
Console.WriteLine("MACAddress: {0}", queryObj("MACAddress"))
Next
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
End Function
End Class
End Namespace

You can strip out what you want and simplify it, there are a lot more network parameters available...good luck.





Re: Visual Basic Language Default Geteway and Subnet Mask how to get them into string?

Rabtok

tempgp wrote:

Oh I got wrong tool,

he code creator gives me the code, but I can find Defult getway


Here is how I got the code I posted.

Load the tool and set Code Language to VB .Net from the Code Language menu.

In the drop down called Classes (Dynaminc or Static) select "Win32_NetworkAdapterConfiguration.

You will then see a results window with a list of parameters, select the parameters you are interested in using standard windows methods (ctrl-click or shift and select). The parameter for Gateway is called "DefaultIPGateway", select that and run the code.

The code appears in the window...





Re: Visual Basic Language Default Geteway and Subnet Mask how to get them into string?

tempgp

Om got the idea how to build the cod but this code if sofe console APP, can i do it for Object Oriented App/ or I have to manually kill the console write




Re: Visual Basic Language Default Geteway and Subnet Mask how to get them into string?

Rabtok

Replace the consolewrite with the variable or form control you want to store the parameter in.


For example, lets take the console code:

If queryObj("DefaultIPGateway") Is Nothing Then
Console.WriteLine("DefaultIPGateway: {0}", queryObj("DefaultIPGateway"))
Else
Dim arrDefaultIPGateway As String()
arrDefaultIPGateway = queryObj("DefaultIPGateway")
For Each arrValue As String In arrDefaultIPGateway
Console.WriteLine("DefaultIPGateway: {0}", arrValue)
Next
End If

Say I have a listbox control on a form called lbGateway...

If queryObj("DefaultIPGateway") Is Nothing Then
lbGateway.items.add(DefaultIPGateway: " + queryObj("DefaultIPGateway").ToString)
Else
Dim arrDefaultIPGateway As String()
arrDefaultIPGateway = queryObj("DefaultIPGateway")
For Each arrValue As String In arrDefaultIPGateway
lbGateway.items.add("DefaultIPGateway: " + arrValue.ToString)
Next
End If

The property may be a string but forcing it does no harm and ensures you get one so I use .ToString in the example.







Re: Visual Basic Language Default Geteway and Subnet Mask how to get them into string?

tempgp

Got ya

Well I also was told in another forum that tere is build in VB2005 functionality

Look at Net.NetworkInformation.NetworkInterface :-)

Much less code to use






Re: Visual Basic Language Default Geteway and Subnet Mask how to get them into string?

Rabtok

not as much fun.






Re: Visual Basic Language Default Geteway and Subnet Mask how to get them into string?

tempgp

what do u mean fun Im lazy :-P

Now i have to find good way to deal with multiple networc cards