cURL实现表单提交登陆计费系统[已解决]
由于本人玩的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>密 码:</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">
第一步必须登陆计费系统:
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
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 编辑 ] http://www.91fd.com/blog/?newid=1151716837 非常感谢HonestQiao
向老法王,致敬!!!
linux下命令行用cURL终于可以实现表单提交登陆计费系统和连接网络,解决了session cookie保存问题。
问题看一楼帖子,现在发现非常的简单,呵呵。
修改代码如下:
这一步实现登陆计费系统,把产生的cookie保存在fee.cookie文件里
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值
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查询可以返回结果了
# nslookup www.chinaunix.net
Server: 10.1.10.197
Address: 10.1.10.197#53
Non-authoritative answer:
Name: www.chinaunix.net
Address: 159.226.63.26 我也研究过这类问题, 随便也拿来 共享一下!!~:em11:
curl -D "/client/GK.txt" -d "spcode=608511&sppassword=sohu332416" "lu.blog.com:80/sp/login.do"
-D 将JSESSIONID 等值放入 GK.txt 文件中
curl -b "JSESSIONID=EC0AE12D30BA57B10AB68E558067B765;" -d "tonetype=0.5" "http://lu.blog.com/sp/UploadServlet?tonetype=0.5"
-b 带入JSESSIONID
-d 以POST方式提交
curl -b "JSESSIONID=AAB5E9FBA659044518C09A18B2310271;" -F file1/childring_file/7/1/爱神厄洛斯的漫游.asf""lu.blog.com/sp/UploadServlet"
-F 上传文件
太强了,这样也行啊 。真是服了!!!! 如果要查看的网页使用了框架怎么办,
<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> 就是喜欢你的帖子 没办法
页:
[1]