如何在VB.NET中将IP地址转换为IP HostEntry?

时间:2013-03-29 04:21:56

标签: vb.net ip ip-address

我正在构建一个小应用程序,在您将其键入到蒙版文本框后会更改您的IP地址。我真的很接近搞清楚,但我需要帮助h = myNewIP部分,因为我无法从IP地址转换为IP主机条目:

Public Class MainForm
Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
Dim myNewIP As System.Net.IPAddress
Dim myIPEndPoint As System.Net.IPEndPoint
Dim strLocalIp As String

Private Sub
        myNewIP = System.Net.IPAddress.Parse(TextBox1.Text)
        myIPEndPoint = New System.Net.IPEndPoint(myNewIP, 0)
        h = myNewIP
        ipTextBox.Text = myNewIP.ToString
End Sub

1 个答案:

答案 0 :(得分:0)

IPEndPoint endpoint = new IPEndPoint(System.Net.IPAddress.Parse("your ip"), 1111);

只是关于这一行的一条建议:

Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
Dim myNewIP As System.Net.IPAddress
Dim myIPEndPoint As System.Net.IPEndPoint
Dim strLocalIp As String

如果在一种方法中使用它们,则只在本地声明它们。