How to convert IP Address to IP HostEntry in VB.NE

2019-08-20 23:12发布

I'm building a small application that will change your IP address after you type it into a masked text box. I'm really close to figuring it out, but I need help with the h = myNewIP part, as I can't convert from an IP address to an IP Host Entry :

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条回答
forever°为你锁心
2楼-- · 2019-08-20 23:28
IPEndPoint endpoint = new IPEndPoint(System.Net.IPAddress.Parse("your ip"), 1111);

Just a piece of advice in relation to this lines:

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

If they are used in one method only declare them locally.

查看更多
登录 后发表回答