vb 6.0 获取本机公网IP[范文]

时间:2019-05-13 14:43:19下载本文作者:会员上传
简介:写写帮文库小编为你整理了多篇相关的《vb 6.0 获取本机公网IP[范文]》,但愿对你工作学习有帮助,当然你在写写帮文库还可以找到更多《vb 6.0 获取本机公网IP[范文]》。

第一篇:vb 6.0 获取本机公网IP[范文]

vb 6.0 获取本机公网IP

Private Declare Function InternetOpen Lib “wininet.dll” Alias “InternetOpenA”(_

ByVal sAgent As String, ByVal lAccessType As Long, _

ByVal sProxyName As String, ByVal sProxyBypass As String, _ByVal lFlags As Long)As Long

Private Declare Function InternetOpenUrl Lib “wininet.dll” Alias

“InternetOpenUrlA”(_

ByVal hInternetSession As Long, ByVal sUrl As String, _

ByVal sHeaders As String, ByVal lHeadersLength As Long, _ByVal lFlags As Long, ByVal lContext As Long)As Long Private Declare Function InternetReadFile Lib “wininet.dll”(_

ByVal hFile As Long, ByVal sBuffer As String, _

ByVal lNumBytesToRead As Long, _

lNumberOfBytesRead As Long)As Integer

Private Declare Function InternetCloseHandle Lib “wininet.dll”(_

ByVal hInet As Long)As Integer

Private Const INTERNET_FLAG_NO_CACHE_WRITE = &H4000000 Private Declare Function URLDownloadToFile Lib “urlmon” Alias

“URLDownloadToFileA”(ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long)As Long

Public Function GetIP()As String

Dim wburl$, wburl2$, X1, X2, X3, X4

On Error GoTo err

wburl = “http:///ip2city.asp”

wburl = GetUrlFile(wburl)

If InStr(1, wburl, “无法找到该页”)= 0 Then

X1 = InStr(1, wburl, “[”)

X2 = InStr(1, wburl, “]”)

X1 = Mid(wburl, X1, X2X3)

X3 = Replace(X3, “

”, “")

X3 = Replace(X3, ” “, ”“)

X3 = Replace(X3, vbCrLf, ”“)

GetIP = X3

Exit Function

Else

GetIP = ”127.0.0.1“

End If

err:

GetIP = ”127.0.0.1“

End Function

Private Function GetUrlFile(stUrl As String)As String

Dim lgInternet As Long, lgSession As Long

Dim stBuf As String * 1024

Dim inRes As Integer

Dim lgRet As Long

Dim stTotal As String

stTotal = vbNullString

lgSession = InternetOpen(”VBTagEdit“, 1, vbNullString, vbNullString, 0)If lgSession Then

lgInternet = InternetOpenUrl(lgSession, stUrl, vbNullString, _0, INTERNET_FLAG_NO_CACHE_WRITE, 0)If lgInternet Then

Do

inRes = InternetReadFile(lgInternet, stBuf, 1024, lgRet)stTotal = stTotal & Mid$(stBuf, 1, lgRet)

Loop While(lgRet <> 0)

End If

inRes = InternetCloseHandle(lgInternet)

End If

GetUrlFile = stTotal

End Function

使用方法:调用GetIP 返回值即为公网IP

Private Sub Command1_Click()

Dim aa As String

Dim strLocalIP As String

Dim winIP As Object

aa = aa & ”本机电脑名称:“ & Environ(”computername“)& vbCrLfaa = aa & ”本机用户名称:“ & Environ(”username“)& vbCrLfSet winIP = CreateObject(”MSWinsock.Winsock“)

strLocalIP = winIP.localip

MsgBox aa & ”本机IP:" & strLocalIP

End Sub

第二篇:PHP 获取客户端真实IP地址多种方法小结

PHP 获取客户端真实IP地址多种方法小结

经过复杂的判断与算是的获取IP地址函数 复制代码 代码如下: function getIP(){

if(getenv('HTTP_CLIENT_IP')){ $ip = getenv('HTTP_CLIENT_IP');}

elseif(getenv('HTTP_X_FORWARDED_FOR')){ $ip = getenv('HTTP_X_FORWARDED_FOR');}

elseif(getenv('HTTP_X_FORWARDED')){ $ip = getenv('HTTP_X_FORWARDED');}

elseif(getenv('HTTP_FORWARDED_FOR')){ $ip = getenv('HTTP_FORWARDED_FOR');} elseif(getenv('HTTP_FORWARDED')){ $ip = getenv('HTTP_FORWARDED');} else {

$ip = $_SERVER['REMOTE_ADDR'];} return $ip;

} 最简单获取ip地址代码一句实例

复制代码 代码如下: $reIP=$_SERVER[“REMOTE_ADDR”];echo $reIP;php获取ip的算法

复制代码 代码如下: if(getenv('HTTP_CLIENT_IP')){ $onlineip = getenv('HTTP_CLIENT_IP');

} elseif(getenv('HTTP_X_FORWARDED_FOR')){ $onlineip = getenv('HTTP_X_FORWARDED_FOR');} elseif(getenv('REMOTE_ADDR')){ $onlineip = getenv('REMOTE_ADDR');} else {

$onlineip = $HTTP_SERVER_VARS['REMOTE_ADDR'];}

echo $onlineip;可以分出内网与外网站ip地址获取程序

复制代码 代码如下: function getip_out(){ $ip=false;

if(!empty($_SERVER[“HTTP_CLIENT_IP”])){ $ip = $_SERVER[“HTTP_CLIENT_IP”];} if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ $ips教程 = explode(“, ”, $_SERVER['HTTP_X_FORWARDED_FOR']);if($ip){ array_unshift($ips, $ip);$ip = FALSE;} for($i = 0;$i < count($ips);$i++){

if(!eregi(“^(10│172.16│192.168).”, $ips[$i])){ $ip = $ips[$i];break;} } }

return($ip ? $ip : $_SERVER['REMOTE_ADDR']);}

echo getip_out();php获取ip的算法,用了?号表达式来处理

复制代码 代码如下: $user_IP =($_SERVER[“HTTP_VIA”])? $_SERVER[“HTTP_X_FORWARDED_FOR”] : $_SERVER[“REMOTE_ADDR”];$user_IP =($user_IP)? $user_IP : $_SERVER[“REMOTE_ADDR”];

下载vb 6.0 获取本机公网IP[范文]word格式文档
下载vb 6.0 获取本机公网IP[范文].doc
将本文档下载到自己电脑,方便修改和收藏,请勿使用迅雷等下载。
点此处下载文档

文档为doc格式


声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:645879355@qq.com 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。

相关范文推荐