10-03-2010, 07:08 PM
(This post was last modified: 10-03-2010, 07:12 PM by AceInfinity.)
Here is an example of a simple app I made with VB2008 to show you how you can retrieve your Local Computer IP Address from your network.
I did not use winsock in this code. Instead I used the function:
You need to put that code in your form load. In my application it's under Public Class form 1.
Then when you add a variable, like a label or a textbox that you want to display the IP. You can call it with:
For example. I used a textbox so my code for the textbox was:
When you debug it, make sure it works. If you want to add the code to display the window on top. The code is:
I just put those in 2 radio buttons because I find it easier to view which option is selected, whether it is enabled or not. And I set the radio button where I wanted the option OFF to be automatically "dotted" when the application starts.
My Icon (Ico):
Application View:
Enjoy
I did not use winsock in this code. Instead I used the function:
Code:
Function ReturnLocalIP(ByVal Type As Net.Sockets.AddressFamily) As String
'Pass "Net.Sockets.AddressFamily.InterNetwork" for IPv4
'Pass "Net.Sockets.AddressFamily.InterNetworkV6" for IPv6
Dim HostEntry As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
For Each IP As Net.IPAddress In HostEntry.AddressList
If IP.AddressFamily = Type Then
Return IP.ToString
End If
Next
Return "NULL"
End Function
You need to put that code in your form load. In my application it's under Public Class form 1.
Then when you add a variable, like a label or a textbox that you want to display the IP. You can call it with:
Code:
(Youre Variable) = ReturnLocalIP(Net.Sockets.AddressFamily.InterNetwork)
For example. I used a textbox so my code for the textbox was:
Code:
TextBox1.Text = ReturnLocalIP(Net.Sockets.AddressFamily.InterNetwork)
When you debug it, make sure it works. If you want to add the code to display the window on top. The code is:
Code:
Me.TopMost = True
and
Me.TopMost = False
I just put those in 2 radio buttons because I find it easier to view which option is selected, whether it is enabled or not. And I set the radio button where I wanted the option OFF to be automatically "dotted" when the application starts.
My Icon (Ico):
Application View:
Enjoy