第一篇: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”];