- 论坛徽章:
- 0
|
我是想屏蔽某些端口 (21)
- static unsigned char *deny_port = "\x15\x00";//port 21
- …
- struct sk_buff *sb = skb;
- struct tcphdr *tcph;
-
- tcph=tcp_hdr(sb);
- if(tcph->source==*(__be16 *)deny_port)
- {
- printk(KERN_INFO "Packet from port 21 Droped\n");
- return NF_DROP;
- }
- …
复制代码 然后我测试连接21端口
#nc -v xx.xx.xx.xx 21
没有成功,还是连接上了,端口没被屏蔽
然后我用printk查看具体端口号
插入三天printk
printk(KERN_INFO "Packet from source port %d \n",tcph->dest);
printk(KERN_INFO "Packet from dest port %d \n",tcph->source);
printk(KERN_INFO "Packet from match port %d \n",*(__be16 *)deny_port);
- struct sk_buff *sb = skb;
- struct tcphdr *tcph;
-
- tcph=tcp_hdr(sb);
- printk(KERN_INFO "Packet from source port %d \n",tcph->dest);
- printk(KERN_INFO "Packet from dest port %d \n",tcph->source);
- printk(KERN_INFO "Packet from match port %d \n",*(__be16 *)deny_port);
- if(tcph->source==*(__be16 *)deny_port)
- {
- printk(KERN_INFO "Packet from port 21 Droped\n");
- return NF_DROP;
- }
复制代码 打印结果如下
命令
nc -v xx.xx.xx.xx 21
[14004.353389] Packet from source port 5376 //源端口
[14004.353394] Packet from dest port 1934 //目的端口
[14004.353397] Packet from match port 21 //我要批评的端口
[14004.431504] Packet from source port 5376
[14004.431508] Packet from dest port 1934
[14004.431510] Packet from match port 21
这是什么原因呢? |
|