<?phpfunction posttohost($url, $data) { $url = parse_url($url); if (!$url) return "couldn't parse url"; if (!isset($url['port'])) { $url['port'] = ""; } if (!isset($url['query'])) { $url['query'] = ""; } $encoded = ""; while (list($k,$v) = each($data)) { $encoded .= ($encoded ? "&" : ""); $encoded .= rawurlencode($k)."=".rawurlencode($v); } $fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80); if (!$fp) return "Failed to open socket to $url[host]"; fputs($fp, sprintf("POST %s%s%s HTTP/1.0\n", $url['path'], $url['query'] ? "?" : "", $url['query']));# fputs($fp, "Host: $url[host]\n"); fputs($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE5.0; Windows NT 5.0)\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\n"); fputs($fp, "Accept: text/html\n"); fputs($fp, "Content-length: " . strlen($encoded) . "\n"); fputs($fp, "Connection: close\n\n"); fputs($fp, "$encoded\n"); $line = fgets($fp,1024); if (!eregi("^HTTP/1\.. 200", $line)) return; $results = ""; $inheader = 1; while(!feof($fp)) { $line = fgets($fp,1024); if ($inheader && ($line == "\n" || $line == "\r\n")) { $inheader = 0; } elseif (!$inheader) { $results .= $line; } } fclose($fp); return $results;}function gettohost($url) { $url = parse_url($url); if (!$url) return "couldn't parse url"; if (!isset($url['port'])) { $url['port'] = ""; } if (!isset($url['query'])) { $url['query'] = ""; } $fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80); if (!$fp) return "Failed to open socket to $url[host]"; fputs($fp, sprintf("GET %s%s%s HTTP/1.0\n", $url['path'], $url['query'] ? "?" : "", $url['query']));# fputs($fp, "Host: $url[host]\n"); fputs($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE5.0; Windows NT 5.0)\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\n"); fputs($fp, "Accept: text/html\n");# fputs($fp, "Content-length: " . strlen($encoded) . "\n"); fputs($fp, "Connection: close\n\n"); $line = fgets($fp,1024); if (!eregi("^HTTP/1\.. 200", $line)) return; $results = ""; $inheader = 1; while(!feof($fp)) { $line = fgets($fp,1024); if ($inheader && ($line == "\n" || $line == "\r\n")) { $inheader = 0; } elseif (!$inheader) { $results .= $line; } } fclose($fp); return $results;}$id = "999999999";$password = "1234";$ip = "172.24.5.28";$url = "[url]http://172.31.130.251/servlet/scpservlet.UserDataReqLoginServlet[/url]";#$url = "[url]http://localhost/test2.php?id=1[/url]";$data = array( 'id' => $id, 'inputpassword' => '', 'servicetype' => '201+', 'ip' => $ip, 'password' => $password, 'languagetype' => '0', 'operatingSystem' => '1', 'httpIp' => '211.95.166.57', 'RadiusVision' => '1', 'Domain' => 'uestc' );$results = posttohost($url, $data);echo $results;$url="[url]http://172.31.130.251/ClientProcess.jspMsgType=100&ISNNO=1000&LocalIP=$ip&UserName=$id&olduserip=$ip&httpIp=211.95.166.57&isPNP=False[/url]";$results = gettohost($url);echo $results;?>
下面是引用零点坐标于2005-06-14 15:45发表的: php本来就可以写shell脚本,perl能做的,php几乎都能做,php也是一种很好的脚本语言。注意安装php为cgi方式就可以了。测试方法:编写test.php:#!/usr/bin/php -q(q参数可以避免输出html标记).......
下面是引用rob于2005-06-14 19:03发表的:o?在win下有没有这样的应用啊?
下面是引用owen于2005-06-16 17:42发表的:关键是fputs($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE5.0; Windows NT 5.0)n");吧
下面是引用rob于2005-06-17 11:34发表的:对了你这个程序在win下能用不?我试试不行啊