Get public IP Address of computer

JasonDaurison 36 Reputation points
2021-04-18T18:40:17.27+00:00

Hello everyone

I am creating a program that needs the public IP Address of the computer it is running on. How would I get it from within code.

Developer technologies VB
0 comments No comments
{count} vote

Accepted answer
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-04-18T19:57:36.247+00:00

    See if this is what you are looking for

    Dim hostName As String = Net.Dns.GetHostName()
    Dim IPAddress As String = Net.Dns.GetHostByName(hostName).AddressList(0).ToString()
    MessageBox.Show($"Host Name: { hostName} IP: {IPAddress}")
    

    You can validate this with a PowerShell one-liner

    Get-NetIPAddress -AddressFamily IPv4 | select IPaddress,Interface* | ConvertTo-Json

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.