设为首页收藏本站淘宝杂货铺

从F到0 - From F to 0

 找回密码
 注册已关闭
搜索
查看: 151|回复: 0
收起左侧

Quartus Verilog HDL/FPGA 判断IPv4地址是否属于广域网外网,或局域网内网等保留无效IP

[复制链接]
发表于 2023-8-25 20:31:54 | 显示全部楼层 |阅读模式
本帖最后由 HDL 于 2023-8-25 20:33 编辑

main.png
  1. module is_wan_ip(                                //IP地址内外网判断模块
  2.         input [31:0] ipv4,                //[32位宽] IPv4地址 例:127.0.0.1 传入:{8'd127,8'd0,8'd0,8'd1}
  3.         output reg wan                                //外网IP传出1,其他IP传出0
  4. );

  5. wire [7:0] a = ipv4[31:24];
  6. wire [7:0] b = ipv4[23:16];
  7. wire [15:0] c = {a,b};

  8. always @(*) begin
  9.         wan = 1'b1;
  10.         if(a == 8'd0 || a == 8'd10 || a == 8'd127 || a >= 8'd224) wan = 1'b0;        //0.*.*.*,10.*.*.*,127.*.*.* 224.0.0.0~255.255.255.255
  11.         if(c == {8'd169,8'd254} || c == {8'd192,8'd168}) wan = 1'b0;                                //169.254.*.*,192.168.*.*
  12.         if(c >= {8'd172,8'd16} && c <= {8'd172,8'd31}) wan = 1'b0;                                        //172.16.0.0 ~ 172.31.255.255
  13. end
  14. endmodule

  15. module main(
  16.         input clk,                        //时钟输入
  17.         output reg led                //低电平(外网IP)点亮
  18. );
  19. wire out;
  20. is_wan_ip is_wan_ip(
  21.         .ipv4({8'd1,8'd2,8'd3,8'd4}),
  22.         .wan(out)
  23. );

  24. always @(posedge clk) begin
  25.         led <= !out;
  26. end
  27. endmodule
复制代码

相关帖子

您需要登录后才可以回帖 登录 | 注册已关闭

本版积分规则

QQ|手机版|Archiver|从F到0 ( 蒙ICP备17002595号-1 )
蒙公网安备15010402000325号

腾讯云安全认证

GMT+8, 2024-4-27 16:46 , Processed in 1.865106 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表