免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 23816 | 回复: 6
打印 上一主题 下一主题

cURL实现表单提交登陆计费系统[已解决] [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-11-27 13:42 |只看该作者 |倒序浏览
由于本人玩的linux要上网,必须登陆计费系统网页,提交用户密码和IP。即:模拟浏览器登陆计费系统
登陆计费系统过程:
计费系统首页提供一个表单:
用户:
密码:
IP:
连接网络 断开网络 帐号管理

表单部分内容:
<FORM method=post action="login.jsp" name=form1 target="_blank">
.....
.....
<TD align=right class=font width=57>用户名:</TD>
          <TD align=left width=165><INPUT type="text" name="user" onmouseover=this.focus() maxLength="24"></TD>
        </TR>
        <TR vAlign=center align=left>
          <TD align=right class=font width=57>密&nbsp;&nbsp;码:</TD>
          <TD width=165><INPUT type="password" name="pass" onmouseover=this.focus() maxLength="24"></TD>
         </TR>
        <TR vAlign=center align=left>
          <TD align=right class=font width=57>注册IP:</TD>
          <td width="248" valign="right">
            <input type="text" name="ip" value=192.168.1.1 size="20" maxlength="16">
...
<INPUT TYPE="hidden" NAME="type" VALUE = "2" CHECKED>
            <INPUT TYPE="hidden" NAME="type" VALUE = "1" >
......
..
<INPUT style="FONT-SIZE: 12px; BACKGROUND-COLOR: rgb(139,217,132)" type=submit value="连接网络" name="action" >
        <INPUT style="FONT-SIZE: 12px; BACKGROUND-COLOR: rgb(139,217,132)" type=submit value="中断连网" name="action">
        <INPUT style="FONT-SIZE: 12px; BACKGROUND-COLOR: rgb(139,217,132)" type=submit value="账号管理" name="action">


第一步必须登陆计费系统:
  1. curl -d"user=test&pass=111111&ip=192.168.1.1&type=2&type=1&action=%C1%AC%BD%D3%CD%F8%C2%E7" 192.168.252.4/login.jsp
复制代码

第二步提交一个网络连接的action
  1. curl "192.168.252.4/user/network/connect_action.jsp?ip=192.168.1.1&type=2"
复制代码

运行第一步操作后,然后运行第二部操作,发现出现“请重新登陆的提示,也就是第一步登陆的session cookie没有保存,导致第二步操作出现问题。

请问版主,如何保存一步的session会话状态,然后第二步操作能够在第一步session的状态下执行网络连接

curl -v http://192.168.252.4 //linux下curl -v查看计费系统显示如下信息:

Accept: */*
Referer: http://192.168.252.4/
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
Host: 192.168.252.4
Content-Length: 87
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=af7DHRWsfwse; CNGASSESSION=ADS2FYAAGKK6A9B2RUJC//会话session
......

[ 本帖最后由 sdglg 于 2006-11-27 14:56 编辑 ]

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
2 [报告]
发表于 2006-11-27 13:56 |只看该作者

论坛徽章:
0
3 [报告]
发表于 2006-11-27 14:54 |只看该作者
非常感谢HonestQiao
向老法王,致敬!!!
linux下命令行用cURL终于可以实现表单提交登陆计费系统和连接网络,解决了session cookie保存问题。
问题看一楼帖子,现在发现非常的简单,呵呵。

修改代码如下:
这一步实现登陆计费系统,把产生的cookie保存在fee.cookie文件里
  1. curl -d "user=test&pass=111111&ip=192.168.1.1&type=2&type=1&action=%C1%AC%BD%D3%CD%F8%C2%E7" --cookie-jar fee.cookie 192.168.252.4/login.jsp
复制代码


这一步实现连接网络,读取上一步产生的session cookie即fee.cookie文件。共享上一步操作的session cookie值
  1. curl --cookie fee.cookie --referer -d "http://192.168.252.4/user/network/connect_action.jsp?ip=192.168.1.1&type=2"
复制代码


联网成功后显示的部分网页代码:
.....
<td align="center" valign="middle" height="26" colSpan="2" class=font1><b>连接结果</b></td>
    </tr>
    <tr>
      <td>
        <br />
        <br />
        联网成功!<br>在不使用网络时,请及时断开网络
........

可以上网了。呵呵,dns查询可以返回结果了

  1. [root@dns2 tmp]# nslookup www.chinaunix.net
  2. Server:         10.1.10.197
  3. Address:        10.1.10.197#53

  4. Non-authoritative answer:
  5. Name:   www.chinaunix.net
  6. Address: 159.226.63.26
复制代码

论坛徽章:
0
4 [报告]
发表于 2006-11-27 15:19 |只看该作者
我也研究过这类问题, 随便也拿来 共享一下!!~:em11:

  1. curl -D "/client/GK.txt" -d "spcode=608511&sppassword=sohu332416" "lu.blog.com:80/sp/login.do"

  2. -D   将JSESSIONID 等值放入 GK.txt 文件中

  3. curl -b "JSESSIONID=EC0AE12D30BA57B10AB68E558067B765;" -d "tonetype=0.5" "http://lu.blog.com/sp/UploadServlet?tonetype=0.5"

  4. -b 带入JSESSIONID
  5. -d 以POST方式提交

  6. curl -b "JSESSIONID=AAB5E9FBA659044518C09A18B2310271;" -F file1/childring_file/7/1/爱神厄洛斯的漫游.asf"  "lu.blog.com/sp/UploadServlet"

  7. -F 上传文件
复制代码

论坛徽章:
0
5 [报告]
发表于 2007-02-16 22:46 |只看该作者
太强了,这样也行啊 。真是服了!!!!

论坛徽章:
0
6 [报告]
发表于 2011-11-23 12:54 |只看该作者
如果要查看的网页使用了框架怎么办,

<frameset rows=102,* cols=* framespacing=0 frameborder=0 border=0>
<frame name=banner scrolling=no noresize target=contents src=title.htm marginwidth=0 marginheight=0>
<frameset rows=* cols=180,*>
<frame name=contents target=main src=menu_admin.htm marginwidth=0 marginheight=0 scrolling=auto>
<frame name=main_screen src=system.htm target=_self scrolling=auto marginwidth=0 marginheight=0 noresize>
</frameset>
<noframes>
<body>
<p>此网页使用了框架,但您的浏览器不支持框架。</p>
</body>
</noframes>
</frameset>

论坛徽章:
0
7 [报告]
发表于 2013-02-03 01:26 |只看该作者
就是喜欢你的帖子 没办法
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP