使用網段網管名單

清華大學校園網路各單位使用網段及網路管理人員資料一覽表

單位網路管理人員如有異動，請填寫【校園網路單位網路管理人員資料表】，後送「計算機與通訊中心 網路系統組」處理。

以下資料限本校 IP 流覽，校外請使用 SSL VPN服務 取得本校 IP。

// 2017/10/19 Turn off all error reporting error_reporting(0); $client_ip = get_client_ip(); if ( cidr_match($client_ip, "140.114.0.0/16") or cidr_match($client_ip, "120.127.160.0/19") ) { // echo "NTHU IP $client_ip\n"; } else { // Not NTHU IP //$wiki_content = " * ** 您的連線 IP $client_ip 非本校 IP ($client_ip is not an NTHU IP address.)** ."; //$info = array(); //echo p_render('xhtml',p_get_instructions($wiki_content),$info); msg("您的連線 IP $client_ip 非本校 IP ($client_ip is not an NTHU IP address.)", -1); return -1; } $CACHE = '/tmp/dokuwiki_netman_list.txt'; $URL = 'https://service.net.nthu.edu.tw/cgi-bin/ip_authority.cgi?password=rooster2017&action=list_all'; $TTL = 600; $arrContextOptions=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, ), ); // check if not exist or out-dated if ( is_file($CACHE) && ((time() - filectime($CACHE)) < $TTL) ) { $str = file_get_contents($CACHE); } else { $str = file_get_contents($URL, false, stream_context_create($arrContextOptions)); // if return, then put contents, else get content if ( strlen($str) > 0) { if ( is_file($CACHE) ) unlink($CACHE); file_put_contents($CACHE, $str); } else { $str = file_get_contents($CACHE); } } $str = iconv('big5', 'utf-8', $str); $txt = ''; // pure text no html foreach ( explode("\n", $str) as $line ) { if ( preg_match('/^<|^\t|^$/', $line) ) continue; // skip unwanted data $txt .= "$line\n"; } //echo "<pre>$txt</pre>"; $lines = explode("\n", $txt); array_pop($lines); // remove the null element at the end of the array //print_r($lines); // debug //usort($lines, sort_by_field0); // sorted by ip_authority.cgi //print_r($lines); // debug $update_time = strftime("%c", filemtime($CACHE)) . ' ' . date_default_timezone_get(); $wiki_content = " * 更新時間：$update_time \n\n"; $wiki_content .= "^ 起始 IP 位址 ^ 結束 IP 位址 ^ 單位 ^ 網管人員 \\\\ 職稱 ^ 電話 \\\\ 傳真 \\\\ 電子郵件信箱 ^\n"; $items_p = array(); // previous line foreach ( $lines as $line ) { $items = explode("\t", $line); // delimiter $items[4] = trim($items[4]); // strip white space $man = explode(",", $items[4]); // delimiter //$wiki_content .= "| $items[0] | $items[1] | $items[2] \\\\ $items[3] | $man[0] \\\\ $man[1] | $man[2] \\\\ $man[3] \\\\ $man[4] |\n"; if ( $items[0] == $items_p[0] ) { $wiki_content .= "| ::: "; } else { $wiki_content .= "| <typo fc:black; fs:100%; ff:Serif;> $items[0] </typo> "; } if ( $items[1] == $items_p[1] ) { $wiki_content .= "| ::: "; } else { $wiki_content .= "| <typo fc:black; fs:100%; ff:Serif;> $items[1] </typo> "; } //if ( $items[2] == $items_p[2] && $items[3] == $items_p[3] ) { if ( $items[2] == $items_p[2] ) { $wiki_content .= "| ::: "; } else { //$wiki_content .= "| $items[2] \\\\ $items[3] "; $wiki_content .= "| $items[2] "; } if ( $items[4] == $items_p[4] ) { $wiki_content .= "| ::: | ::: |\n"; } else { //$wiki_content .= "| $man[0] \\\\ $man[1] |$man[2] \\\\ $man[3] \\\\ <$man[4]> |\n"; // 2017/09/07 rewrite email format $email = str_replace('@', " :AT: ", $man[4]); $wiki_content .= "| $man[0] \\\\ $man[1] |$man[2] \\\\ $man[3] \\\\ $email |\n"; } $items_p = $items; // previous one } $info = array(); echo p_render('xhtml',p_get_instructions($wiki_content),$info); // Function to get the client IP address function get_client_ip() { $ipaddress = ''; if (isset($_SERVER['HTTP_CLIENT_IP'])) $ipaddress = $_SERVER['HTTP_CLIENT_IP']; else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; else if(isset($_SERVER['HTTP_X_FORWARDED'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED']; else if(isset($_SERVER['HTTP_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_FORWARDED_FOR']; else if(isset($_SERVER['HTTP_FORWARDED'])) $ipaddress = $_SERVER['HTTP_FORWARDED']; else if(isset($_SERVER['REMOTE_ADDR'])) $ipaddress = $_SERVER['REMOTE_ADDR']; else $ipaddress = 'UNKNOWN'; return $ipaddress; } function cidr_match($ip, $range) { list ($subnet, $bits) = explode('/', $range); $ip = ip2long($ip); $subnet = ip2long($subnet); $mask = -1 << (32 - $bits); $subnet &= $mask; return ($ip & $mask) == $subnet; } function sort_by_field0($a, $b) { // "^ 起始 IP 位址 ^ 結束 IP 位址 ^ 單位 ^ Area ^ 網管人員 ^\n"; $af = explode("\t", $a); $bf = explode("\t", $b); // delimiter // 起始 IP 位址 $aip = sprintf('%u', ip2long($af[0])); $bip = sprintf('%u', ip2long($bf[0])); if ( $aip != $bip ) return ($aip > $bip); // 網管人員: utf8中文字無法以筆劃排序，要解決這個問題，可以將字碼轉成big5後排序 $af[4] = iconv('utf-8', 'big5', $af[4]); $bf[4] = iconv('utf-8', 'big5', $bf[4]); return strcmp($af[4], $bf[4]) ; }