查找我的IP地址 [英] finiding my ip address
本文介绍了查找我的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写代码来查找我的IP地址,我正在使用此代码
i am writing a code to find my ip address and i am using this code
private string GetIP()
{
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
return addr[addr.Length - 1].ToString();
}
but it returns me 192.168.1.2 . which but it is not globle ip .
推荐答案
我会有一个阅读本文
http://dotnetpgm.blogspot.co.uk/2009/09/how-to-get-ip-address-in-aspnet.html [ ^ ]
I would have a read of this article
http://dotnetpgm.blogspot.co.uk/2009/09/how-to-get-ip-address-in-aspnet.html[^]
Private Function IPAddress() As String
Dim strIP As String = ""
Dim LocalHostName As String
Try
LocalHostName = Dns.GetHostName() //Here u will get ur system Name
Dim ipEnter As IPHostEntry = Dns.GetHostEntry(LocalHostName)
Dim IpAdd() As IPAddress = ipEnter.AddressList
strIP = IpAdd(0).ToString()
Return strIP //It will return ipaddress of ur system
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Function
使用C#CODE - >
With C# CODE-->
private string IPAddress()
{
string strIP = "";
string LocalHostName = null;
try {
LocalHostName = Dns.GetHostName();
IPHostEntry ipEnter = Dns.GetHostEntry(LocalHostName);
IPAddress[] IpAdd = ipEnter.AddressList;
strIP = IpAdd(0).ToString();
return strIP;
} catch (Exception ex) {
throw new Exception(ex.Message);
}
}
这篇关于查找我的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文