如何在VB.NET中将IP地址转换为IP HostEntry? [英] How to convert IP Address to IP HostEntry in VB.NET?

查看:226
本文介绍了如何在VB.NET中将IP地址转换为IP HostEntry?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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


推荐答案

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.

这篇关于如何在VB.NET中将IP地址转换为IP HostEntry?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆