给服务器添加端口映射服务
2016-04-30 22:39
274 查看
用于校区实验室服务器上的自助端口映射脚本。
portmgr.c
portmgr.php
portmgr.c
#include <stdio.h> #define IPTABLES "/sbin/iptables" int main(int argc, char *argv[]) { char *iptables_argv[512] = { IPTABLES, "-tnat" }; int i = 2; if (argc >= 2) { switch(*argv[1]) { case 'a': iptables_argv[i++] = "-A"; break; case 'd': iptables_argv[i++] = "-D"; break; default: iptables_argv[i++] = "--line-numbers"; iptables_argv[i++] = "-nvL"; } iptables_argv[i++] = "prerouting_port_forwarding"; int j; for(j = 2; j<argc; ++j) iptables_argv[i++] = argv[j]; return execv(IPTABLES, iptables_argv); } return 0; }
portmgr.php
switch($_SERVER["REQUEST_METHOD"]) { case "GET": echo "<body><pre>"; passthru("./portmgr l"); echo "</pre></body>"; exit; case "POST": switch($_POST["cmd"]) { case "a": if ($_POST["dport"] && !empty($_POST["to"])) { //if ($_POST["dport"] === "80" || $_POST["dport"] === "http") { // $msg = "不能为80(http)端口"; // break; //} else $proto = " -p tcp --dport " . $_POST["dport"]; if (!empty($_POST["dst"])) $dst = "-d ". $_POST["dst"]; else $dst = ""; passthru("./portmgr a " . $dst . $proto . " -j DNAT --to " . $_POST["to"], $ret); if ($ret === 0) $msg = "操作成功"; } break; case "d": if (!empty($_POST["id"])) { passthru("./portmgr d " . $_POST["id"], $ret); if ($ret === 0) $msg = "操作成功"; } break; } break; }
相关文章推荐
- 大量JAVA系列教学视频免费学习
- 读书养人
- 基于OpenCV和Android的运动目标检测系统
- 求高精度幂(java)
- 典型jsp用户注册处理页面
- JS设计模式
- Java中的数学类
- (转)国内外三个不同领域巨头分享的Redis实战经验及使用场景
- launcher 长按拖动流程
- CodeForces - 246B Increase and Decrease (模拟)水
- 基于用户投票的排名算法:威尔逊区间
- 给定字符串查找子串,返回子串出现的位置
- NoSQL概念
- CSS3学习笔记
- Oculus调试工具
- 备忘录模式
- Linux Mysql 双机热备安装详解
- Adam学习13之Fasta/Fastq/SAM/BAM文件格式数据读取
- javascript笔记—— 构造函数
- Fedora如何添加第三方软件源?