How to convert IP Address to IP HostEntry in VB.NET?

﹥>﹥吖頭↗ 提交于 2019-12-13 04:26:56

问题


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:


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.



来源:https://stackoverflow.com/questions/15697299/how-to-convert-ip-address-to-ip-hostentry-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!