|
本帖最后由 HDL 于 2023-8-25 20:33 编辑
- module is_wan_ip( //IP地址内外网判断模块
- input [31:0] ipv4, //[32位宽] IPv4地址 例:127.0.0.1 传入:{8'd127,8'd0,8'd0,8'd1}
- output reg wan //外网IP传出1,其他IP传出0
- );
- wire [7:0] a = ipv4[31:24];
- wire [7:0] b = ipv4[23:16];
- wire [15:0] c = {a,b};
- always @(*) begin
- wan = 1'b1;
- 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
- if(c == {8'd169,8'd254} || c == {8'd192,8'd168}) wan = 1'b0; //169.254.*.*,192.168.*.*
- if(c >= {8'd172,8'd16} && c <= {8'd172,8'd31}) wan = 1'b0; //172.16.0.0 ~ 172.31.255.255
- end
- endmodule
- module main(
- input clk, //时钟输入
- output reg led //低电平(外网IP)点亮
- );
- wire out;
- is_wan_ip is_wan_ip(
- .ipv4({8'd1,8'd2,8'd3,8'd4}),
- .wan(out)
- );
- always @(posedge clk) begin
- led <= !out;
- end
- endmodule
复制代码 |
|