473,797 Members | 3,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there an easy way to get my Subnet Mask?

I am using VB 2005. I can't seem to find a way to get my local Subnet Mask.
The only thing mentioned from googling is the GetIpAddrTable API, but so
far, i've had no luck getting a call to it working. Another idea was to
traverse the registry at
HKLM/System/CurrentControlS et/Services/Tcpip/Parameters/Interfaces. But
that seems really sloppy. One would think that VB 2005 would have a
My.Computer.Net work.Subnet property.
Apr 29 '06 #1
2 8257
I have figured out a way to do it, although not quite "elegant"

Imports Microsoft.Win32
Imports System.Net

Public Class Form1

Dim regPath As String =
"System\Current ControlSet\Serv ices\Tcpip\Para meters\Interfac es\"

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim x As RegistryKey = My.Computer.Reg istry.LocalMach ine.OpenSubKey( regPath,
False)
For Each skn As String In x.GetSubKeyName s
Dim y As RegistryKey =
My.Computer.Reg istry.LocalMach ine.OpenSubKey( regPath & skn, False)
Dim z As Integer = y.GetValue("Ena bleDHCP")
If z = 1 Then
Try
If y.GetValue("Dhc pIPAddress").To String =
Dns.GetHostAddr esses(Dns.GetHo stName)(0).ToSt ring Then
MsgBox("DHCP: " & y.GetValue("Dhc pSubnetMask"))
Exit Sub
End If
Catch
End Try
Else
Try
If y.GetValue("IPA ddress").ToStri ng =
Dns.GetHostAddr esses(Dns.GetHo stName)(0).ToSt ring Then
MsgBox("STATIC: " & y.GetValue("Sub netMask"))
Exit Sub
End If
Catch
End Try
End If
y.Close()
Next
x.Close()
End Sub

End Class
Apr 29 '06 #2
Terry,

Using IPConfig as command gives you in a string your subnetmask if you want
that filtering it than using regex or simple using indexof should give you
the result you want..

Using than this you get the string
\\\
Public Class Test
Public Shared Sub Main()
Dim p As New Process
Dim pi As New ProcessStartInf o
pi.UseShellExec ute = False
pi.RedirectStan dardOutput = True
pi.WorkingDirec tory = "C:\windows\sys tem32"
'this for nt* computers
pi.FileName = "ipconfig"
p.StartInfo = pi
p.StartInfo = pi
p.Start()
Dim sr As IO.StreamReader = p.StandardOutpu t
Dim sb As New System.Text.Str ingBuilder("")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW( input))
input = sr.Read
Loop
MessageBox.Show (sb.ToString)
End Sub
End Class
///

I hope this helps,

Cor

"Terry Olsen" <to******@hotma il.com> schreef in bericht
news:ee******** ******@TK2MSFTN GP02.phx.gbl...
I am using VB 2005. I can't seem to find a way to get my local Subnet Mask.
The only thing mentioned from googling is the GetIpAddrTable API, but so
far, i've had no luck getting a call to it working. Another idea was to
traverse the registry at
HKLM/System/CurrentControlS et/Services/Tcpip/Parameters/Interfaces. But
that seems really sloppy. One would think that VB 2005 would have a
My.Computer.Ne twork.Subnet property.

Apr 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
9117
by: Chandrashekar Tippur | last post by:
Pros, I was wondering if there is a API for generating ip address range from a given subnet mask (VLSM). Thanks, Shekar
0
1685
by: Pierre Rouleau | last post by:
Hi all, socket.gethostbyname_ex(socket.gethostname()) will return the list of IP addresses on a the local host. I did not find any function that can be used to get the subnet mask and default gateway. Under Win32, the Win32 IP helper API provides a GetIpAddrTable() function that returns information that contain the subnet mask, but that's Win32 level, and is not portable. Is there something available in the Python library for that...
1
2520
by: sam | last post by:
Hi, This is a C programming specific with TCP/IP relation. Supposed I have two string (char *) variables with the following assignment: ip_str = "10.1.2.3" netmask_str = "255.255.0.0" How can I use C programming technique to get the subnet 10.1.0.0? I tried to use "struct in_addr", but not sure how to start writing a
6
19980
by: ohynes | last post by:
hey newbie here wondering if there is anyone out there who can help me im trying to make a c# subnet calulator using the IPAddress class i cant seem to figure out how to do all the subnet calculations now i can do them on paper but thats about it just starting to learn c sharp
1
2480
by: Glenn M | last post by:
I know how i can use request.userhostaddress to get the requesting ip address. is their any way i can get the requesting clients subnet mask also?
1
2422
by: JamesB | last post by:
I'm looking for a function to return true/false depending on if two supplied IP's (as strings) are in the same subnet (also supplied). Im getting nowhere fast unfortunately - I know the theory behind it, but I have no idea on how to actually implement it! I have split my supplied 3 IP's into 4 numbers each, but past that I'm stuck - on paper I would convert them to binary and write down all the 1's and 0's then figure it out, but in...
3
1865
by: JamesB | last post by:
Hmm, this doesn't seem to work. I am probably tackling it completely the wrong way, but basically I want a function to receive two IP's and a subnet mask and return True if IP1 and 2 are on the same subnet, otherwise false. I have got this so far: Private Function IsSameSubnet(ByVal IPSource As String, ByVal IPDest As String, ByVal IPSubnet As String) As Boolean
5
8918
by: wright.brandt | last post by:
I am new to programming in C. If my question is not appropriate for this newsgroup I apologize. I Have been tasked with writing a small application to do some back end processing in C and have had little trouble getting most of the app written. What seems to be holding me up is a tricky (at least for me) piece of network address logic. I need to be able to take an ip address and compare it to a subnet represented in the doted and slashed...
2
3108
by: nussu | last post by:
Hi , I need to find a subnet mask number for a given IP Address number. I have two textbox's once enter the ip address in first textbox i need to get subnet mask number for that ip address in second textbox. Please help me by providing links or c#.net code. Thanks in Advance. Regards, Nussu
0
10468
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10245
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.