Get/Display IP Address of my Computer

I want an Button to form that will display my computer's IP address,, how can I do this? Thanks in advance.
Rowel VirgoVisual Studio .NETAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dr. KlahnPrincipal Software EngineerCommented:
Do you want the IP address of your computer on the local network, or the IP address of the internet-facing router?  The two are not the same and the second is more difficult to obtain.
0
Rowel VirgoVisual Studio .NETAuthor Commented:
Of my computer sir.,
0
Dr. KlahnPrincipal Software EngineerCommented:
Here's an article on how to obtain the IP address in VB and return it with a button.

https://stackoverflow.com/questions/2234757/how-do-i-get-a-computers-name-and-ip-address-using-vb-net

See the commentary that begins "Shows the Computer Name, Use a Button to call it"
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Shaun VermaakTechnical SpecialistCommented:
You can use this in the button
Dim strComputerName As String
Dim strIPAddress As String

strComputerName = System.Net.Dns.GetHostName()
strIPAddress = System.Net.Dns.GetHostByName(strComputerName).AddressList(0).ToString()

Open in new window

1
it_saigeDeveloperCommented:
I have personally never liked the heavy handed approach of querying a remote entity for my local information (especially if you may not have access to said entity).  To that end, I prefer to use something based on GetIPProperties instead:
Imports System.Net.NetworkInformation
Imports System.Net.Sockets

Module Module1
	Sub Main()
		For Each adapter In NetworkInterface.GetAllNetworkInterfaces()
			Dim addresses = adapter.GetIPProperties().UnicastAddresses
			Dim gateways = adapter.GetIPProperties().GatewayAddresses
			Dim dns = adapter.GetIPProperties().DnsAddresses
			Console.WriteLine($"Adapter: {adapter.Description}")
			Console.WriteLine($"IPv6 Address: {String.Join(", ", From address In addresses Where address.Address.AddressFamily = AddressFamily.InterNetworkV6 Select address.Address)}")
			Console.WriteLine($"IPv4 Address: {String.Join(", ", From address In addresses Where address.Address.AddressFamily = AddressFamily.InterNetwork Select address.Address)}")
			Console.WriteLine($"Subnet Mask: {String.Join(", ", From address In addresses Where address.Address.AddressFamily = AddressFamily.InterNetwork Select address.IPv4Mask)}")
			Console.WriteLine($"Default Gateway: {String.Join(", ", From gateway In gateways Select gateway.Address)}")
			Console.WriteLine($"DNS: {String.Join(", ", From address In dns Select address)}")
			Console.WriteLine()
		Next
		Console.ReadLine()
	End Sub
End Module

Open in new window

Which produces the following output -Capture.PNG
-saige-
1
Rowel VirgoVisual Studio .NETAuthor Commented:
I did this:



    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        dbConnect()
        GetIPAddr()
    End Sub

--------------------------------------------------------------------------------------------------------------------------------------------------------

    Private Sub GetIPAddr()
        Dim hostName As String
        Dim ipAddr() As IPAddress

        hostName = System.Net.Dns.GetHostName()
        ipAddr = Dns.GetHostAddresses(hostName)

        For i = 1 To ipAddr.Count - 1
            Label4.Text = ipAddr(i).ToString
        Next
    End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.