LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: zest

铁通WEB认证方式上网在Linux下已经搞定

[复制链接]
发表于 2004-4-3 11:24:11 | 显示全部楼层
看不懂前面的代码?
刚刚接触LINUX.什么都不懂~
学校里用华为的WEB认证上网的
http://211.90.225.62/index.jsp
在LINUX下用浏览器不能通过.
发表于 2004-4-3 11:24:12 | 显示全部楼层
看不懂前面的代码?
刚刚接触LINUX.什么都不懂~
学校里用华为的WEB认证上网的
http://211.90.225.62/index.jsp
在LINUX下用浏览器不能通过.
 楼主| 发表于 2004-4-3 11:55:53 | 显示全部楼层
这篇文章中说得完整些:

  1. [url]http://linuxsir.cn/postnuke/modules.php?op=modload&name=News&file=article&sid=1066&mode=thread&order=0&thold=0[/url]
复制代码


实际你的认证页面与我的一样,按文章中的方法试试,将代码中的 ip 地址,用户名,密码改改就能用。
发表于 2004-4-3 11:57:56 | 显示全部楼层
谢谢
先试试
发表于 2004-4-3 12:25:29 | 显示全部楼层
代码看不懂.
能帮我分析一下吗?
发表于 2004-4-3 14:42:34 | 显示全部楼层
还是不会弄
我把代码贴上去.帮我分析一下
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

        <title>宽带网络,建造世纪新生活!</title>                 

<script language="JavaScript" src="/httpsurl.js">
</script>
<SCRIPT LANGUAGE="JavaScript" >

             function languageSelect()
             {            
                    var i=window.document.fm0.languagetype.value;
                    window.parent.location.href="/index.jsp?newbl="+i;
             }

                          var ifwait=false;
                          function iwait(t){
                            if(ifwait==true){
                              return true;
                            }else{
                              ifwait=true;
                              window.setTimeout("ifwait=false;",t);
                              return false;
                            }
                          }                                      
            
             function ipvalue()
             {
                window.document.fm0.ip.value = PortalClient.localIP;                 
                      if (((window.document.fm0.ip.value).toLowerCase()=="undefined")||(window.document.fm0.ip.value==""))  {
                               if (window.document.fm0.languagetype.value=="1") {
                                    //zhaihuachun IT20PT-26-E12540 2002-09-16  begin
                                    //zhaihuachun IT20PT-17-E12476 2002-09-12  begin
                                    if (PortalClient.localIP=="") {
                                      window.alert("网络繁忙,请稍后重试");
                                    } else  {
                                      window.alert("请下载系统签名证书");
                                    window.parent.location.href="/index.jsp?newbl=1";
                                  }  
                               } else {
                                    if (PortalClient.localIP=="") {
                                      window.alert("Net Busy, Please try later");
                                    } else  {
                                      window.alert("lease allow system to download the necessary certificate");                                 
                                    window.parent.location.href="/index.jsp?newbl=0";                                     
                                  }
                               }
                               //zhaihuachun IT20PT-26-E12540 2002-09-16  end
                              return false;
                      }                                
                return true;           
             }
            
                    
             function pwdcode(moreFlag)
             {
                        var iw=iwait(5000);
                        if(iw) return false;             
                if(check(moreFlag))
                {
                     var url=gethttpsurl();
                     url=url.substring(url.indexOf('//'));
                     url=url.substring(2, url.length-10);                                                      
                     pswd=window.document.fm0.inputpassword.value;
                     
                     if (ipvalue())
                     {
                                                if(pswd!="") window.document.fm0.password.value = pswd;
                                                  window.document.fm0.action='https://'+url+'/servlet/scpservlet.UserDataReqLoginServlet';
                                             var Then = new Date()        
                             Then.setTime(Then.getTime() + 60*1000*60*24*365 )   //60秒                                 
                                             if (window.document.fm0.saveflag.checked)
                                             {                                                  
                                document.cookie = "username="+window.document.fm0.id.value+";expires="+ Then.toGMTString() ;
                                document.cookie = "password="+window.document.fm0.password.value+";expires="+ Then.toGMTString() ;
                                document.cookie = "saveflag=1;expires="+ Then.toGMTString() ;
                             }
                             else
                             {
                                       document.cookie = "username="+window.document.fm0.id.value+";expires="+ Then.toGMTString() ;
                                       document.cookie = "password="+""+";expires="+ Then.toGMTString() ;
                                document.cookie = "saveflag=0;expires="+ Then.toGMTString() ;
                             }                                                                                 
                                          return true;
                                     }
                                 }
                        return false;
             }
                                                                         
             function close_online()
             {
             var url=gethttpsurl();
             url=url.substring(0, url.length-10);                                                                   
                            window.fm0.action=url+"/servlet/scpservlet.CloseReqServlet";
                         return true;
             }

  </SCRIPT>
  
          <SCRIPT LANGUAGE="JavaScript" src="/portalserver/eg20.js"></SCRIPT>


</head>

<body bgcolor="" background="" >
<center>



<div style="visibility:hidden">
<OBJECT
   id="ortalClient"
   classid="clsid:817C90B5-1688-42BE-9044-58422DB088B2"
   codebase=http://211.90.225.62:80/PortalAX.cab#version=1,0,1,2
    width=10
    height=10
>
  <param name='httpPrefix' value='http://211.90.225.62:80'>
  <param name='httpsPrefix' value='https://211.90.225.62:443'>
  <param name='LogEnabled' value='false'>
</OBJECT>
</div>

<script language='javascript'>
  PortalClient.init_var();  
</script>


<table bgcolor="#FFFFFF" border="0" cellpadding="0" Align="center" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="770" id="AutoNumbe1">
<tr >
   <td width="100%"  align="center" >
              
       <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>宽带网络,建造世纪新生活!</title>
<table border="0" width="770" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td width="100%" background="/homepage/bg.jpg" height="300">
      <table border="0" width="100%" cellspacing="0" cellpadding="0">
      </table>
    </td>
  </tr>
</table>
</body>
</html>   
      
   </td>   
</tr>   
</table>  

  <DIV id=Layer1
style="HEIGHT: 48px; LEFT: 200px; POSITION: absolute; TOP: 100px; WIDTH: 660px; Z-INDEX: 3">
<TABLE border=0 height=33 width="70%" >
       <TBODY>
      <TR>
           <td width="30%">
           </td>
           <td width="30%">
           </td>           
           <td width="40%">
               
               
        </TD>
      </TR>
         
</TBODY>
</TABLE></DIV>

<table bgcolor="#33CC33" border="0" cellpadding="0" Align="center" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="770" id="AutoNumber2">
<form name="fm0" method="post"  target = "_parent" >
  <tr style="font-size: 9pt">   
      <td width="100%" Align="center" style="font-size: 9pt" nowrap>      
        <font color="#FFFFFF" ><b>账号</b></font><input type="text" name="id"  value="a5716153@kjcc" size="10" title="请输入用户名!" maxlength="32">
        <font color="#FFFFFF" ><b>密码</b></font><input type="password" name="inputpassword"  value="855734"   title="请输入密码!" size="10" maxlength="16">      
        <input type="checkbox" name="saveflag" value="1" checked >记住密码
        <font color="#FFFFFF"><b>语言</font></b>
        <select name="languagetype"  onChange="languageSelect(); ">
                <option value="1" selected> 中文 </option>
                <option value="0"> English </option>
        </select>        
        <input type="submit" name="Submit" value="连 接"  onclick="return pwdcode(0)">
         <a style="color: #ffffff; cursor:hand;" HREF  onClick="this.style.behavior='url(#default#homepage)';this.setHomePage(gethttpsurl());">设为首页</a>
        <a style="color: #ffffff; text-decoration: none" href="javascript:window.external.addFavorite(gethttpsurl(),'宽带认证首页')">添加收藏</a>            
        
      </td>   
  </tr>   
  <tr>
    <td width="100%" style="line-height: 150%" bgcolor="#FFFFFF" height="1">
        <input type = "hidden" name = "ip">
        <input type = "hidden" name = "ClientIP">
        <input type = "hidden" name = "ipmode" value="0">
        <input type="hidden" name="password" value="" title="Hidden Encrypt Password!" size="23" maxlength="16">            
        <input type=hidden name="LocalIP" value="">            
    </td>
  </tr>     
  </form>
</table>

<table bgcolor="#5555ff" border="0" cellpadding="0" Align="center" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="770" id="AutoNumber3">
  <tr style="font-size: 9pt">
    <td>   
    <img src="" width=0 height=5><br>
    <font color="#dddddd">
   
    &nbsp;&nbsp;1.在您首次访问本页面时,如果自动下载签名证书失败,请点击此处
    <a href="/signPortal.exe" style="color: #ffff00; font-size: 13; text-decoration: none">手工下载本证书并进行注册</a>,有疑问请见
    <a href="/template/ax_help.html" style="color: #ffff00; font-size: 13; text-decoration: none">“首次上网帮助”。</a><br>
   
    &nbsp;&nbsp;2.为了方便您访问我们的网站,不用每次确认安装证书,请安装
    <a href ="ca.crt" target="_blank" style="color: #ffff00; font-size: 13; text-decoration: none">“安全证书”</a>,有疑问请见
    <a href="/template/ssl_help.html" style="color: #ffff00; font-size: 13; text-decoration: none">“安装指导”。</a><br>
    &nbsp;&nbsp;3.如果您的浏览器字体显示异常,请安装<a target="_blank" href="ielpkzhc.exe" style="color: #ffff00; font-size: 13; text-decoration: none">“简体中文包”。</a><br>
    <div align="center">建议使用800*600分辨率,IE4.01或更高版本浏览器,如果您还有其它上网问题,请尝试将浏览器恢复默认设置。<br>
    除特别声明外,其余内容版权由华为公司所有。</div>
    </font>
    </td>
发表于 2004-4-3 15:23:18 | 显示全部楼层
搞定了 谢谢
 楼主| 发表于 2004-4-4 11:14:07 | 显示全部楼层
怎么做的?
说说看。
发表于 2004-4-4 19:30:45 | 显示全部楼层
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>宽带网络,建造世纪新生活!</title>

<script language="JavaScript" src="/httpsurl.js">
</script>
<SCRIPT LANGUAGE="JavaScript" >

function languageSelect()
{
var i=window.document.fm0.languagetype.value;
window.parent.location.href="/index.jsp?newbl="+i;
}

var ifwait=false;
function iwait(t){
if(ifwait==true){
return true;
}else{
ifwait=true;
window.setTimeout("ifwait=false;",t);
return false;
}
}

function ipvalue()
{
window.document.fm0.ip.value = PortalClient.localIP; 改为'本地IP'
if (((window.document.fm0.ip.value).toLowerCase()=="undefined")||(window.document.fm0.ip.value=="")) {
if (window.document.fm0.languagetype.value=="1") {
//zhaihuachun IT20PT-26-E12540 2002-09-16 begin
//zhaihuachun IT20PT-17-E12476 2002-09-12 begin
if (PortalClient.localIP=="") {
window.alert("网络繁忙,请稍后重试");
} else {
window.alert("请下载系统签名证书");
window.parent.location.href="/index.jsp?newbl=1";
}
} else {
if (PortalClient.localIP=="") {
window.alert("Net Busy, Please try later");
} else {
window.alert("lease allow system to download the necessary certificate");
window.parent.location.href="/index.jsp?newbl=0";
}
}
//zhaihuachun IT20PT-26-E12540 2002-09-16 end
return false;
}
return true;
}


function pwdcode(moreFlag)
{
var iw=iwait(5000);
if(iw) return false;
if(check(moreFlag))
{
var url=gethttpsurl();
url=url.substring(url.indexOf('//'));
url=url.substring(2, url.length-10);
pswd=window.document.fm0.inputpassword.value;

if (ipvalue())
{
if(pswd!="") window.document.fm0.password.value = pswd;
window.document.fm0.action='https://'+url+'(改为服务器IP)/servlet/scpservlet.UserDataReqLoginServlet';
var Then = new Date()
Then.setTime(Then.getTime() + 60*1000*60*24*365 ) //60秒
if (window.document.fm0.saveflag.checked)
{
document.cookie = "username="+window.document.fm0.id.value+";expires="+ Then.toGMTString() ;
document.cookie = "password="+window.document.fm0.password.value+";expires="+ Then.toGMTString() ;
document.cookie = "saveflag=1;expires="+ Then.toGMTString() ;
}
else
{
document.cookie = "username="+window.document.fm0.id.value+";expires="+ Then.toGMTString() ;
document.cookie = "password="+""+";expires="+ Then.toGMTString() ;
document.cookie = "saveflag=0;expires="+ Then.toGMTString() ;
}
return true;
}
}
return false;
}

function close_online()
{
var url=gethttpsurl();
url=url.substring(0, url.length-10);
window.fm0.action=url+"/servlet/scpservlet.CloseReqServlet";
return true;
}

</SCRIPT>

<SCRIPT LANGUAGE="JavaScript" src="/portalserver/eg20.js"></SCRIPT>


</head>

<body bgcolor="" background="" >
<center>



<div style="visibility:hidden">
<OBJECT
id="ortalClient"
classid="clsid:817C90B5-1688-42BE-9044-58422DB088B2"
codebase=http://211.90.225.62:80/PortalAX.cab#version=1,0,1,2
width=10
height=10
>
<param name='httpPrefix' value='http://211.90.225.62:80'>
<param name='httpsPrefix' value='https://211.90.225.62:443'>
<param name='LogEnabled' value='false'>
</OBJECT>
</div>

<script language='javascript'>
PortalClient.init_var();
</script>


<table bgcolor="#FFFFFF" border="0" cellpadding="0" Align="center" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="770" id="AutoNumbe1">
<tr >
<td width="100%" align="center" >

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>宽带网络,建造世纪新生活!</title>
<table border="0" width="770" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="100%" background="/homepage/bg.jpg" height="300">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
</table>
</td>
</tr>
</table>
</body>
</html>

</td>
</tr>
</table>

<DIV id=Layer1
style="HEIGHT: 48px; LEFT: 200px; POSITION: absolute; TOP: 100px; WIDTH: 660px; Z-INDEX: 3">
<TABLE border=0 height=33 width="70%" >
<TBODY>
<TR>
<td width="30%">
</td>
<td width="30%">
</td>
<td width="40%">


</TD>
</TR>

</TBODY>
</TABLE></DIV>

<table bgcolor="#33CC33" border="0" cellpadding="0" Align="center" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="770" id="AutoNumber2">
<form name="fm0" method="post" target = "_parent" >
<tr style="font-size: 9pt">
<td width="100%" Align="center" style="font-size: 9pt" nowrap>
<font color="#FFFFFF" ><b>账号</b></font><input type="text" name="id" value="a5716153@kjcc" size="10" title="请输入用户名!" maxlength="32">
<font color="#FFFFFF" ><b>密码</b></font><input type="password" name="inputpassword" value="855734" title="请输入密码!" size="10" maxlength="16">
<input type="checkbox" name="saveflag" value="1" checked >记住密码
<font color="#FFFFFF"><b>语言</font></b>
<select name="languagetype" onChange="languageSelect(); ">
<option value="1" selected> 中文 </option>
<option value="0"> English </option>
</select>
<input type="submit" name="Submit" value="连 接" onclick="return pwdcode(0)">
<a style="color: #ffffff; cursor:hand;" HREF onClick="this.style.behavior='url(#default#homepage)';this.setHomePage(gethttpsurl());">设为首页</a>
<a style="color: #ffffff; text-decoration: none" href="javascript:window.external.addFavorite(gethttpsurl(),'宽带认证首页')">添加收藏</a>

</td>
</tr>
<tr>
<td width="100%" style="line-height: 150%" bgcolor="#FFFFFF" height="1">
<input type = "hidden" name = "ip">
<input type = "hidden" name = "ClientIP">
<input type = "hidden" name = "ipmode" value="0">
<input type="hidden" name="password" value="" title="Hidden Encrypt Password!" size="23" maxlength="16">
<input type=hidden name="LocalIP" value="">
</td>
</tr>
</form>
</table>

<table bgcolor="#5555ff" border="0" cellpadding="0" Align="center" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="770" id="AutoNumber3">
<tr style="font-size: 9pt">
<td>
<img src="" width=0 height=5><br>
<font color="#dddddd">

  1.在您首次访问本页面时,如果自动下载签名证书失败,请点击此处
<a href="/signPortal.exe" style="color: #ffff00; font-size: 13; text-decoration: none">手工下载本证书并进行注册</a>,有疑问请见
<a href="/template/ax_help.html" style="color: #ffff00; font-size: 13; text-decoration: none">“首次上网帮助”。</a><br>

  2.为了方便您访问我们的网站,不用每次确认安装证书,请安装
<a href ="ca.crt" target="_blank" style="color: #ffff00; font-size: 13; text-decoration: none">“安全证书”</a>,有疑问请见
<a href="/template/ssl_help.html" style="color: #ffff00; font-size: 13; text-decoration: none">“安装指导”。</a><br>
  3.如果您的浏览器字体显示异常,请安装<a target="_blank" href="ielpkzhc.exe" style="color: #ffff00; font-size: 13; text-decoration: none">“简体中文包”。</a><br>
<div align="center">建议使用800*600分辨率,IE4.01或更高版本浏览器,如果您还有其它上网问题,请尝试将浏览器恢复默认设置。<br>
除特别声明外,其余内容版权由华为公司所有。</div>
</font>
</td>
发表于 2004-4-9 02:07:50 | 显示全部楼层

这是我的,大家参考一下吧

在这里首先要感谢zest,没有他的帮助,我无法这么轻松的搞定, 这里的代码是以他的代码为原型的.感谢他的大公无私.


说明一下, 我的上网方式需要SSL方式
也就是必须通过SSL发送登陆信息,  所以就必须使用OpenSSL了

需要Python的HTTPlib支持SSL

我在SuSE 8.2下, 虽然缺省安装了Python, 但是并不支持SSL,
执行HTTPS访问是, 说什么SSL模块没有安装

如果是这样,那么就需要重新安装Python了

我先down了一个openssl-0.9.7d.tar.gz

安装这个openssl

然后down了Python-2.3.3.tgz

先./configure,
make
make install

这时候就已经可以使用python了,
可以敲个python试试, 如果没有就试试python2.3

然后到Python-2.3.3.tgz的解压目录中
python2.3 setup.py build_ext -I/usr/local/ssl/include -L/usr/local/ssl/lib
(当然前提是你的openssl安装到这两个目录下了,这是缺省目录)
python2.3 setup.py build
python2.3 setup.py install

这样就重新安装了包,并且把ssl也安装进去了.

这时再使用https就不会包错了




##
#    bash的脚本
#
#    这一段是照着zest抄的
#    目的是为了获取当前网卡的IP地址
#    因为用的是动态获取IP的方式,所以每次IP都不同
#    我不回用Python获取当前网卡的IP,所以就只好这样凑合一下了
##


# 获取 ip 地址
MYIP=`ifconfig eth0|grep inet|sed 's/^ *//'|sed 's/ /:/g'|cut -f3 -d:`
#echo $MYIP

python2.3 testssl.py --ip=$MYIP  > tmpcurl



下面看看我们的主角testssl.py, 原谅我起了一个这样的名字,



import string, getopt, sys, httplib, urllib

try:
    opts, args = getopt.getopt(sys.argv[1:], "hi:", ["help", "ip="])
except getopt.GetoptError:
    # print help information and exit:
    usage()
    sys.exit(2)
ip = None
for o, a in opts:
    if o in ("-h", "--help"):
        usage()
        sys.exit()
    if o in ("-i", "--ip"):
        ip = a

print ip


#下面的这个IP就是你的认证服务器的IP,这个是我的,你要换成你自己的哦!
HOSTNAME = '61.236.216.67'
conn = httplib.HTTPSConnection(HOSTNAME)
headers = {'Accept': 'text/html', 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
'Content-Type': 'application/x-www-form-urlencoded'}


#第一步,  发送请求,这个目的就是为了获取一个sessionID
#http://61.236.216.67
conn = httplib.HTTPConnection(HOSTNAME)

headers = {'Accept': 'text/html', 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
'Content-Type': 'application/x-www-form-urlencoded'
}

print headers
conn.request('GET', '/', None, headers)
response = conn.getresponse()
s = response.read()

print "========first response========"
print s

cookie = response.getheader("Set-Cookie")

headers = {'Accept': 'text/html', 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
'Content-Type': 'application/x-www-form-urlencoded',
'Cookie': cookie
}
#就是这个cookie
print "=====Cookie====", cookie




#这一步我这里不能少, 需要发送自己的IP, 这里的IP在后面会和刚才session联系起来, 以后keep-alive的参数要用到
#second http://61.236.216.67/webLogin.jsp
conn = httplib.HTTPConnection(HOSTNAME)

conn.request('POST', '/webLogin.jsp', "LocalIP=" + ip, headers)
response = conn.getresponse()
s = response.read()

print "========first response========"
print s



print "=====headers====", headers



#第三步, 这是最关键的一步,  就是发送认证信息的请求
#third    https://61.236.216.67:443/secu/webLogin.jsp
params = urllib.urlencode({'connectname': '',
'connecttype': -1,
'consumeright': 0,
'separatecard': 0,
'localip': ip,
'IsIndex': 0,
'username': [这里写你的上网帐号,就是用户名,最好用单引号括起来,没有外面的中括号],
'password': [这里写你的口令,最好用单引号括起来,没有外面的中括号],
'cookiedate': 0})

print params

conn.request('POST', '/secu/webLogin.jsp', params, headers)
response = conn.getresponse()
s = response.read()
start = string.find(s, HOSTNAME)
end = string.find(s, "')", start)
s = s[start:end]
URL = s
cookie2 = response.getheader("Set-Cookie")
print URL
print "cookie2----->>>",cookie2


#第四步, 获取注册信息,这是keep-alive的关键步骤,这里的请求地址是上个response返回的.
#four    get regist parameters
conn = httplib.HTTPConnection(HOSTNAME)


headers = {'Accept': 'text/html', 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
'Content-Type': 'application/x-www-form-urlencoded',
'Cookie': cookie
}
start = string.find(URL, "/")
end =  string.find(URL, "?", start)
URL2 = URL[start:end]
params = URL[end+1:]
print "========deal response========"
print URL2, headers
print "=====params====", params

conn.request('GET', URL2, params, headers)
response = conn.getresponse()
s = response.read()
print s
start = string.find(s, "ortalClient.loginsuc(")
end = string.find(s, ");", start)
print s[start:end]
print "kl-session=",cookie
print "get-session=",response.getheader("Set-Cookie")


#loginstr = s[start:end]

loginstr = s[start + 23:end]
loginstr = string.replace(loginstr, "\r", "")
loginstr = string.replace(loginstr, "\n", "")
loginstr = string.replace(loginstr, " ", "")
loginstr = string.replace(loginstr, "'", "")
print loginstr


L = string.split(loginstr, ',')
print L

user = L[0]
isnno = '1204'
loginkey = L[6]
ip = L[7]


#第五步, 这时已经获取了注册信息,但是还不能keep-alive, 这一步是请求一个新的sessionID, 这个ID才是keep-alive用的
path = '/ClientProcess.jsp?MsgType=2&UserName=' + user + '&LocalIP=' + ip + '&ConnectType=1&ConsumeRight=0&ISNNO=' + isnno + '&LoginKey=' + loginkey

print path

conn = httplib.HTTPConnection(HOSTNAME)


headers = {'Accept': 'text/html', 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)'}

conn.request('GET', path, None, headers)
response = conn.getresponse()

kl_cookie = response.getheader("Set-Cookie")
print "kl_cookie=",kl_cookie
#好了,终于获取了所有要的参数, 收工了.





看看kl.py吧




import string, getopt, sys, httplib, urllib

def main():
    #这里要读取刚才输出的tmpcurl文件, 所以一定不要认为那个文件没有用就删除掉,
    f = open("/这里是绝对路径/tmpcurl")

    print keepalive(f.read())


def keepalive(loginstring):
    #这个是认证服务器的IP
    server = '61.236.216.67'
    mark = "ortalClient.loginsuc('"
    start = string.find(loginstring, mark)
    end = string.find(loginstring, ");", start)
    loginstr = loginstring[start + 23:end]
    loginstr = string.replace(loginstr, "\r", "")
    loginstr = string.replace(loginstr, "\n", "")
    loginstr = string.replace(loginstr, " ", "")
    loginstr = string.replace(loginstr, "'", "")
    print loginstr

    L = string.split(loginstr, ',')
    #获取到我们需要的注册信息
    print L

    user = L[0]
    msgtype = L[4]
    isnno = '1204'
    loginkey = L[6]
    ip = L[7]
    #获取到我们keep-alive的sessionID,就是最后那个请求的session
    #get session
    start = string.find(loginstring, 'kl_cookie=')
    end = string.find(loginstring, ';', start)
    cookie = loginstring[start+11:end+1]


    path = '/ClientProcess.jsp?MsgType=1&LocalIP=' + ip + '&ISNNO=' + isnno + '&LoginKey=' + loginkey

    print path, cookie

    req = httplib.HTTP(server)
    req.putrequest('GET', path)
    req.putheader('Accept', 'text/html')
    req.putheader('User-Agent', 'Mozilla')
    req.putheader('Cookie', cookie)
    req.endheaders()
    ec, em, h = req.getreply()
    fd = req.getfile()

    return fd.read(), (ec, em)

if __name__ == "__main__":
    main()



好了,现在,你只要每10分钟记得运行一下kl.py就好了,,但是有点累, 还是让linux做吧

用corn来做吧,
写个文件,里面就一句话:
*/5 * * * *     python /绝对路径/kl.py
然后用
corntab 文件名
注册这个文件,

好了,万事大吉了.好好上网吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表