如何使用vb.net获取我的真实IP?如何使用vb.net获取我的真实IP?
2
A
回答
2
如果您在ASP.NET运行时,然后使用HttpRequest.UserHostAddress property:
Dim ip as string
ip = Request.UserHostAddress()
0
正如你可以看到here(如何以及为什么),获取客户端IP的最好办法是:
Dim clientIP As String
Dim ip As String = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If Not String.IsNullOrEmpty(ip) Then
Dim ipRange As String() = ip.Trim().Split(","C)
Dim le As Integer = ipRange.Length - 1
clientIP = ipRange(le)
Else
clientIP = Request.ServerVariables("REMOTE_ADDR")
End If
0
Dim req As HttpWebRequest = WebRequest.Create("http://whatismyip.com/automation/n09230945.asp")
Dim res As HttpWebResponse = req.GetResponse()
Dim Stream As Stream = res.GetResponseStream()
Dim sr As StreamReader = New StreamReader(Stream)
MsgBox(sr.ReadToEnd())
1
创建php脚本。将其另存为realip.php
<?php
echo $this->getRealIpAddr();
function getRealIpAddr()
{
$ip = "";
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
?>
在您的VB.net项目中创建一个模块。 声明在最高层
Imports System.Net
Imports System.IO
进口部分并创建功能:
Public Function GetIP() As String
Dim uri_val As New Uri("http://yourdomain.com/realip.php")
Dim request As HttpWebRequest = HttpWebRequest.Create(uri_val)
request.Method = WebRequestMethods.Http.Get
Dim response As HttpWebResponse = request.GetResponse()
Dim reader As New StreamReader(response.GetResponseStream())
Dim myIP As String = reader.ReadToEnd()
response.Close()
Return myIP
End Function
现在,在你的代码的任何地方,你可以发出
Dim myIP as String = GetIP()
从那里使用的值你希望。
相关问题
- 1. 用VB.NET获取“真实”IP地址?
- 2. 如何使用clearsilver库获取真实客户端IP
- 3. 如何使用IOCP获取客户端的真实IP地址和端口?
- 4. 如何使用仿真器获取IP地址的Android
- 5. 在vb.net获取IP地址
- 6. 用Rails和Nginx获取客户端的真实IP地址?
- 7. 即使使用TOR + cURL + PHP,Facebook仍会获得我真实的IP
- 8. 如何使用我的Rails控制台获取有效的真实性令牌?
- 9. 获取本地Rails开发环境中的真实IP地址
- 10. 如何从Jquery获取真实对象?
- 11. 如何隐藏我的真实IP地址?
- 12. 如何使用NativeScript获取本地IP
- 13. 获取使用VB.net
- 14. 如何使用VB.NET获取计算机的名称和IP地址?
- 15. 如何使用CarrierWave从S3获取真实文件
- 16. 如何使用webdav从inotify获取真实姓名
- 17. 检查真实IP IP地址的NodeJS
- 18. 如何使用vb.net代码获取SQL Server实例路径
- 19. 获取使用的IP
- 20. ghost如何从nginx(反向代理)获得真实IP?
- 21. 从Google Cloud Load Balancer和cloudflare获取真实ip
- 22. (已解决)IIS - 在CloudFlare后面获取真实IP地址?
- 23. 获取我的IP地址
- 24. 如何使用Rails获取客户端IP和服务器IP
- 25. 如何在linux中使用ioctl获取网关ip和nameserver ip
- 26. 如何获得aws实例,因为我有实例的ip
- 27. 使用VBScript获取WAN IP
- 28. 使用VB.net获取音高
- 29. 如何获取本地IP?
- 30. 如何获取IP地址?
没有任何IP地址比其他任何IP地址都“真实”,所以您真正想要的是哪个IP地址? – Guffa 2011-02-25 23:53:14
@Guffa可能127.0.0.1:P但这只是形而上学的猜测 – 2011-02-25 23:54:11
@Federico Culloca:诅咒你!打我吧... – 2011-02-25 23:57:23