如何使用VB.NET获取计算机的编程名称和静态IP地址?

时间:2016-04-19 18:37:51

标签: vb.net vb.net-2010

Public Function GetComputerName() As String
    Dim ComputerName As String
    ComputerName = System.Net.Dns.GetHostName
    Return ComputerName
End Function

1 个答案:

答案 0 :(得分:2)

对于PC名称使用:

 My.Computer.Name

供IP使用:

 Private Sub GetIPAddress()

 Dim strHostName As String 
 Dim strIPAddress As String

 strHostName = System.Net.Dns.GetHostName()

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


MessageBox.Show("Host Name: " & strHostName & "; IP Address: " & strIPAddress)

End Sub