linux定時調用指定url鏈接


因為有台電腦做服務器,用的是PPPOE撥號,IP是動態的。萬一IP更換需要知道服務的IP地址。

 

1、找一個空間,放一個asp的程序:

ip.asp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
</head>
<%
function createfile(byval content,byval filedir)
 on error resume next
 dim obj : set obj = server.createobject("adodb.Stream")
 obj.type = 2
 obj.open
 obj.charset = "GB2312"
 obj.position = obj.Size
 obj.writeText = content
 obj.savetofile server.mappath(filedir), 2
 obj.close
 if err then err.clear: createfile = false else createfile = true
 set obj = nothing
End function

Function GetIP()
 Dim strIPAddr
 If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" Or InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
  strIPAddr = Request.ServerVariables("REMOTE_ADDR")
 ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
  strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
 ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
  strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
 Else
  strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
 End If
 getIP = Checkstr(Trim(Mid(strIPAddr, 1, 30)))
 If getIP="" then getIP="127.0.0.1"
End Function

Function CheckStr(str)
 CheckStr=replace(replace(replace(replace(str,"<","&lt;"),">","&gt;"),chr(13),"")," ","")
 CheckStr=replace(replace(replace(replace(CheckStr,"'",""),"and",""),"insert",""),"set","")
 CheckStr=replace(replace(replace(replace(CheckStr,"select",""),"update",""),"delete",""),chr(34),"")
 CheckStr=replace(replace(replace(replace(CheckStr,"*",""),"=",""),"mid",""),"count","")
 CheckStr=replace(replace(replace(replace(CheckStr,"%",""),",",""),"union",""),"where","")
 CheckStr=replace(replace(replace(replace(replace(CheckStr,"(",""),")",""),Chr(0),""),"+",""),";","")
end Function
%>
<body>
<%
response.Write(GetIP()&"<Br>")
if(createfile(GetIP(),"ip.html")) then
 response.Write("IP寫入成功!")
 else
 response.Write("IP寫入失敗!")
end if
%>
</body>
</html>

 

2、然后在linux端安裝小型的瀏覽器:lynx

apt-get install lynx

3、編輯cron任務

/etc/crontab加入

0 * * * * root   lynx -dump http://XXX/ip.asp

這樣服務器每小時就可以訪問一次指定網址。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM