From 949891e3661dde56c628da39b079c7bbfc585f37 Mon Sep 17 00:00:00 2001 From: flykhan Date: Thu, 21 Sep 2023 15:45:46 +0800 Subject: [PATCH] =?UTF-8?q?router=E6=A8=A1=E5=9D=97:=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E8=8F=9C=E5=8D=95,=20=E6=B3=A8=E9=94=80=E5=8E=9F=E5=A7=8B?= =?UTF-8?q?=E5=A5=97=E6=8E=A5=E5=AD=97=E7=9B=B8=E5=85=B3=20(=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E4=BA=86libpcap=E8=BF=9B=E8=A1=8C=E6=8D=95=E8=8E=B7?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=8B=86=E5=8C=85,=20=E4=BD=BF=E7=94=A8libne?= =?UTF-8?q?t=E8=BF=9B=E8=A1=8C=E6=95=B0=E6=8D=AE=E7=BB=84=E8=A3=85?= =?UTF-8?q?=E5=8F=91=E5=8C=85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/router | Bin 0 -> 24632 bytes router/router.c | 51 ++++++++++++++++++++++++------------------------ router/router.h | 2 +- 3 files changed, 26 insertions(+), 27 deletions(-) create mode 100755 router/router diff --git a/router/router b/router/router new file mode 100755 index 0000000000000000000000000000000000000000..e5c91c6cb9c569070ef4e7d75a63d635f3a89b14 GIT binary patch literal 24632 zcmeHvdwf*Yz3<8k!owseDx%dX3I;S|5+DU1WkNEz!v`cqP+P^xV!X1PAMRyTHUyX^AsNGMWtR;>M5Ed<5yJGkLpJMD`feKR2w+r zZA4fpKaNn6rBvP@bW%PupR=Ggo>BBQ0W(FF-VdNhaemvBBL$aBe`f8HFXLBKori1c z+*L($uBmh8)ww;P^?B>(73CGpu?D=>LSApOPqH`Ow32&L?PviyvU;9s4$ZC#d>hIHFF!iw-eAO8#O@11_*uRpuDW@Tkg zNAo9H|Ksl4E;;qPkF!u@n%pQkH%aMN2rwDG5CJ5^mzl^nn#j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coD z;oW1}<|^K*+@Y#E5E46Z@m;OrMbu_h@u+CNkxjyq_X|GRh-i)7PHt$HTt{}i_-)LR ziwesHM$>$7C71r@-R00?)edS0zQGvZrz^h3#?8^h5a!#XnfOZF`77R5;%0WV?;U20 z(YxL;YhXh?-l_%-`US03IqY@j^81+8;|;p3#S6>wf|aW!x7ri3@^hbu-fJbUwlYx5 ztj-M{*b_A97bR<5{(#%-iDMin^SkOQNkQg(*t*Wjd!H3q>uN7px^6HlZ!oLh%eOMK zy0AwaUo_M@VMK94Rb0M>hRWYn4KcW>tan!<25*qe1EGDk9&V2sr%V#KVkJeNfvWil_z>R{;@>U^;e|Yz>VzJYvJ6;LH%x0NC7fNeRY34 zCN0Z{C+V4&j&@(LMU){fdT0VGF=U9fJ`%&_1 zpij@l6tC{{PmvE6Tcl%(pW;;UOPFm$hT2r=tLFi`rGCB?RQ{E|s{dxGzfj7l=LWq} zUp)sTebPzP-vNyJAH_#W?Vo9zBzWBEic5*-KY~)DzIqN(A@zBs4Hj}_UeSjW_2vEV zipfGy#j8vt@{cFztNS)Ssb46m(pP>J|4f3udhYvdu8>gAKb3r9{eL0#)%jD;N!q3U ztu(j{DKY+6QDz+f>UoOVH~Te%E@cz_(|vcNzIyJ`B|FYU>U4&b=>Kh$W#M0msr%My zAMHf>ME*VKW*hX?bDZ8A03s#IC-Q%W48^bftLG(s-%@`7x@v48t3MY~`<&B$y_8h{ zR{m8#XhoUPzj}T&w1BIb#;@#roS?5iXR-9-tlo|c2`#>$lLP^D`Oej6Y ze~k=bs{PdcmNu#1n&97}6eXqS7$hRQi(abq=jw>aD07O^Fju~fqIcaYxQR+o7ACOV ow;DS}{oZ21waOPVE(JRW|Em6K{-g1k%)f7$(Elo7{3ZJT-)4v7>i_@% literal 0 HcmV?d00001 diff --git a/router/router.c b/router/router.c index f4b11c3..4fee16b 100644 --- a/router/router.c +++ b/router/router.c @@ -14,7 +14,7 @@ int main(int argc, char const *argv[]) // pthread_create(&thread_net_task, NULL, net_task, NULL); // pthread_join(thread_net_task, NULL); - close(sockfd); // 关闭原始套接字 + // close(sockfd); // 关闭原始套接字 close_mysql(); // 关闭数据库连接 // 关闭网络设备 @@ -27,12 +27,12 @@ int main(int argc, char const *argv[]) void net_init() { // 创建原始套接字 - sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); // 参数列表:协议族、套接字类型、协议类型 - if (sockfd < 0) - { - perror("socket"); - exit(-1); - } + // sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); // 参数列表:协议族、套接字类型、协议类型 + // if (sockfd < 0) + // { + // perror("socket"); + // exit(-1); + // } // 数据连接测试 if (connect_mysql("localhost", 3306, "flykhan", "1202", "router") == 0) @@ -87,17 +87,22 @@ void printResult(MYSQL_ROW row, char (*columns)[30], int cols) void show() { - printf("************************************************\n"); - printf("**********路由器黑名单管理系统******************\n"); - printf("**************1.添加黑名单IP********************\n"); - printf("**************2.显示所有黑名单******************\n"); - printf("**************3.删除黑名单**********************\n"); - printf("**************4.开启路由器**********************\n"); - printf("**************5.刷新ARP表缓存*******************\n"); - printf("**************6.显示所有ARP表缓存***************\n"); - printf("**************9.重新打印菜单********************\n"); - printf("**************0.退出此系统**********************\n"); - printf("************************************************\n"); + printf("**************************************************\n"); + printf("** **\n"); + printf("** 模拟路由后端管理系统 **\n"); + printf("** **\n"); + printf("** 1.添加黑名单IP **\n"); + printf("** 2.显示所有黑名单 **\n"); + printf("** 3.删除黑名单 **\n"); + printf("** 4.开启路由器 **\n"); + printf("** 5.刷新ARP表缓存 **\n"); + printf("** 6.显示所有ARP表缓存 **\n"); + printf("** 9.重新打印菜单 **\n"); + printf("** 0.退出此系统 **\n"); + printf("** **\n"); + printf("**************************************************\n"); + printf("********** 版权所有 FLY-NOOB **********\n"); + printf("**************************************************\n"); } // 判断IP地址格式是否正确 @@ -188,6 +193,7 @@ void menu_choice() // 后端查询黑名单 ip else if (2 == choice) { + printf("黑名单列表如下:\n"); const char *select_ip_fw_sql = "select * from ip_fw"; query(select_ip_fw_sql, printResult); } @@ -249,6 +255,7 @@ void menu_choice() // 显示 ARP 表 else if (6 == choice) { + printf("ARP 表如下:\n"); const char *select_arp_result_sql = "select * from ip_mac"; query(select_arp_result_sql, printResult); } @@ -262,14 +269,6 @@ void menu_choice() // 退出此系统 else if (0 == choice) { - - close(sockfd); // 关闭原始套接字 - close_mysql(); // 关闭数据库连接 - - // 关闭网络设备 - pcap_close(device1); - pcap_close(device2); - printf("退出此系统\n"); return; } diff --git a/router/router.h b/router/router.h index 983963c..fd8996a 100644 --- a/router/router.h +++ b/router/router.h @@ -21,7 +21,7 @@ #include // 正则表达式,用于ip地址检查 // 定义全局变量 -int sockfd; // 原始套接字 +// int sockfd; // 原始套接字 int ret; // 调用数据库的返回值 char *errmsg; // 错误信息 char **dbResult;