| | |
Get local IP address
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jan 2006
Posts: 6
Reputation:
Solved Threads: 0
I am trying to make an application for deploying to all our workstations at work. I am using VB.NET to create a Windows application. What I need to have done is for the app to open up and display the IP address, MAC address and computer name in text boxes. I need the IP address to be broken down into its 4 octets and each octet populate its own text box (TextBox1-TextBox4).
Anyone have an idea on how to do it?
What I have so far is the IP address part:
Private Sub IPAddress()
'To get local address
Dim LocalHostName As String
Dim i As Integer
LocalHostName = Dns.GetHostName()
Dim ipEnter As IPHostEntry = Dns.GetHostByName(LocalHostName)
Dim IpAdd() As IPAddress = ipEnter.AddressList
For i = 0 To IpAdd.GetUpperBound(0)
Next
End Sub
Anyone have an idea on how to do it?
What I have so far is the IP address part:
Private Sub IPAddress()
'To get local address
Dim LocalHostName As String
Dim i As Integer
LocalHostName = Dns.GetHostName()
Dim ipEnter As IPHostEntry = Dns.GetHostByName(LocalHostName)
Dim IpAdd() As IPAddress = ipEnter.AddressList
For i = 0 To IpAdd.GetUpperBound(0)
Next
End Sub
•
•
Join Date: Jan 2006
Posts: 6
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by f1 fan
use System.Management classes to do it. Writing WMI queries. Have a look at it and if you are stuck let me know and i will give you some code.
My variable is:
'To get local IP address
Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)
'
And in the area for the text box:
Me.TextBox1.Text = h.AddressList.GetValue(0).ToString
•
•
Join Date: Jan 2006
Posts: 275
Reputation:
Solved Threads: 11
oh ok i thought you were trying to get the MAC and other things too.
your dns is in the form xxx.xxx.xxx.xxx
so there is a clue. it is DELIMITED by the . (period)
so instead of your textbox1.text = h.AddressList.GetValue(0).ToString
dim ipfull as string = h.AddressList.GetValue(0).ToString
dim ipsplit as string[] = ipfull.split(".".tochararray[])
you now have an array in ipsplit.
textbox1.text = ipsplit[0]
textbox2.text = ipsplit[1]
textbox3.text = ipsplit[2]
textbox4.text = ipsplit[3]
all done
your dns is in the form xxx.xxx.xxx.xxx
so there is a clue. it is DELIMITED by the . (period)
so instead of your textbox1.text = h.AddressList.GetValue(0).ToString
dim ipfull as string = h.AddressList.GetValue(0).ToString
dim ipsplit as string[] = ipfull.split(".".tochararray[])
you now have an array in ipsplit.
textbox1.text = ipsplit[0]
textbox2.text = ipsplit[1]
textbox3.text = ipsplit[2]
textbox4.text = ipsplit[3]
all done
•
•
Join Date: Jan 2006
Posts: 6
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by f1 fan
oh ok i thought you were trying to get the MAC and other things too.
your dns is in the form xxx.xxx.xxx.xxx
so there is a clue. it is DELIMITED by the . (period)
so instead of your textbox1.text = h.AddressList.GetValue(0).ToString
dim ipfull as string = h.AddressList.GetValue(0).ToString
dim ipsplit as string[] = ipfull.split(".".tochararray[])
you now have an array in ipsplit.
textbox1.text = ipsplit[0]
textbox2.text = ipsplit[1]
textbox3.text = ipsplit[2]
textbox4.text = ipsplit[3]
all done
•
•
Join Date: Jan 2006
Posts: 6
Reputation:
Solved Threads: 0
Well crud!!
I tested the app on another machine that has a 1394 adapter as the first network adapter, and the app pulled THAT MAC. How do I make it pull the active MAC that the IP address is working on and how do I make my text box display just that MAC?
Here is the current code for the MAC :
'To get MAC Address
Dim mc As System.Management.ManagementClass
Dim mo As ManagementObject
mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo In moc
If mo.Item("IPEnabled") = True Then
End If
Next
And the current relevant code for the text box:
Me.TextBox5.Text = mo.Item("MacAddress").ToString()
I know something goes in the If Then statement, but everything I tried caused some type of error.
I tested the app on another machine that has a 1394 adapter as the first network adapter, and the app pulled THAT MAC. How do I make it pull the active MAC that the IP address is working on and how do I make my text box display just that MAC?
Here is the current code for the MAC :
'To get MAC Address
Dim mc As System.Management.ManagementClass
Dim mo As ManagementObject
mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo In moc
If mo.Item("IPEnabled") = True Then
End If
Next
And the current relevant code for the text box:
Me.TextBox5.Text = mo.Item("MacAddress").ToString()
I know something goes in the If Then statement, but everything I tried caused some type of error.
•
•
Join Date: Jan 2006
Posts: 6
Reputation:
Solved Threads: 0
OK, I figured it out!! Yay me!!
'To get MAC Address
Dim mc As System.Management.ManagementClass
Dim mo As ManagementObject
mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
Dim mac as string
For Each mo In moc
If mo.Item("IPEnabled") = True Then
mo.Item("MacAddress").ToString
End If
Next
And the current relevant code for the text box:
Me.TextBox5.Text = mac
'To get MAC Address
Dim mc As System.Management.ManagementClass
Dim mo As ManagementObject
mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
Dim mac as string
For Each mo In moc
If mo.Item("IPEnabled") = True Then
mo.Item("MacAddress").ToString
End If
Next
And the current relevant code for the text box:
Me.TextBox5.Text = mac
![]() |
Similar Threads
- Host's Non-Local IP Address (Java)
- IP address lookup.... (Network Security)
- help in C, Find local Ip address (C)
Other Threads in the VB.NET Forum
- Previous Thread: timer in VB.net
- Next Thread: Can Visio files be converted into web-form for visual studio ?
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account array basic beginner browser button buttons center check client code convert crystalreport cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic dropdownlist eclipse excel fade file-dialog filter forms ftp generatetags gridview html images inline input insert intel internet listview mobile monitor net objects open output panel passingparameters pdf picturebox port position print printing problem read remove save searchbox searchvb.net select serial settings shutdown soap sqlserver survey table tcp temperature textbox timer timespan transparency trim update user vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode year





