Created
January 21, 2014 08:37
-
-
Save zetavg/8536345 to your computer and use it in GitHub Desktop.
`/NTUST-GetWebFlow.php?ip=140.118.x.x`
`$ php NTUST-GetWebFlow.php 140.118.x.x`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 請求 | |
if (defined('STDIN')) { | |
$IP = $argv[1]; | |
} else { | |
$IP = $_GET['ip']; | |
} | |
// 領表單 | |
$url = 'http://netweb.ntust.edu.tw/dormweb/flowquery.aspx'; | |
$formHTML = file_get_contents($url); | |
preg_match_all('/<input.*name="([^"]*)".*value="([^"]*)".*>/m', $formHTML, $formInputs); | |
$formInputs_count = count($formInputs[1]); | |
for ($i=0; $i<$formInputs_count; $i++) { | |
$data[$formInputs[1][$i]] = $formInputs[2][$i]; | |
} | |
// 填表單 | |
$data['un'] = 'MB'; | |
$data['un_v'] = '1000000'; | |
$data['ipdata'] = $IP; | |
$data['sel_str'] = "IP = '" . str_replace($data['hip'], "", $data['ipdata']) . "' and dodate='" . $data['do_date'] . "'"; | |
$data['RB_1'] = '詳細流量查詢'; | |
$data['tot_rows'] = 145; | |
// 遞表單 | |
$options = array( | |
'http' => array( | |
'header' => "Content-type: application/x-www-form-urlencoded\r\nHost: netweb.ntust.edu.tw\r\nOrigin: http://netweb.ntust.edu.tw\r\nReferer: http://netweb.ntust.edu.tw/dormweb/flowquery.aspx", | |
'method' => 'POST', | |
'content' => http_build_query($data), | |
), | |
); | |
$context = stream_context_create($options); | |
$result = file_get_contents($url, false, $context); | |
// 讀回應 | |
$result = str_replace(',', "", $result); | |
if (!preg_match('/grid_tit/m', $result, $totalFlow)) die('ERROR RESPONSE'); | |
if (!preg_match('/<input.*name="tablelist:_ctl3:tid1".*value=" *([0-9]+) *".*>/m', $result, $totalFlow)) $totalFlow[1] = 0; | |
$totalFlow = $totalFlow[1]; | |
// 給資料 | |
echo $totalFlow | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment