VB 2008获得一个网站的IP地址? [英] vb 2008 get an ip address of a website?

查看:104
本文介绍了VB 2008获得一个网站的IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有以下代码,它获取了我设置的本地ip地址,因此我需要处理一些事情:

Hi,

I have the following code which gets the local ip address which I set up so I have something to work on:

Dim ipEntry As IPHostEntry = Dns.GetHostByName(Environment.MachineName)
        Dim IpAddr As IPAddress() = ipEntry.AddressList
        Dim i As Integer

        TextBox3.Text = IpAddr(0).ToString()



上面的代码在文本框中显示了本地ip地址,但是我的问题是如何更改代码,以便vb获取在名为"textbox2"的文本框中输入的网站的ip地址?

在此先感谢任何帮助者



The above code displays the local ip address in a textbox but my question is how do I change the code so vb gets the ip address of a website entered in a textbox called ''textbox2''?

Thanks in advance to any helpers

推荐答案

而不是使用Environment.MachineName,请使用TextBox2.Text.


首先.添加try...catch.异常文本可能会对您有所帮助.
First. Add try...catch. An exception text may help you.


Try
	Dim ipEntry As IPHostEntry = Dns.GetHostByName(TextBox1.Text)
	Dim IpAddr As IPAddress() = ipEntry.AddressList
	Dim i As Integer

	TextBox3.Text = IpAddr(0).ToString()

	Dim hostname As IPHostEntry = Dns.GetHostEntry(TextBox1.Text)
	Dim ip As IPAddress() = hostname.AddressList

	TextBox3.Text = ip(0).ToString()

Catch ex As Exception
	TextBox3.Text = ex.ToString()
End Try



然后,您将看到引起我异常的原因.我不是VB.NET编码器,所以无法测试代码.



Then you''ll see what caused an exception I suppose. I am not VB.NET coder, so I cannot test the code.


这篇关于VB 2008获得一个网站的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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