循环ip段 转载 出处不明
public
struct
IP
{
public
byte
A;
public
byte
B;
public
byte
C;
public
byte
D;
public
IP(
byte
[] ba)
{
A = ba[0];
B = ba[1];
C = ba[2];
D = ba[3];
}
}
public
static
void
IPSection(IPAddress ip1, IPAddress ip2)
{
IP x =
new
IP(ip1.GetAddressBytes());
IP y =
new
IP(ip2.GetAddressBytes());
byte
secStart = 1;
//这里可以改为0
byte
secEnd = 254;
//这里可以改为255
for
(
byte
a = x.A; a <= y.A; a++)
{
byte
bStart = (a == x.A ? x.B : secStart);
byte
bEnd = (a == y.A ? y.B : secEnd);
for
(
byte
b = bStart; b <= bEnd; b++)
{
byte
cStart = (a == x.A && b == x.B) ? x.C : secStart;
byte
cEnd = (a == y.A && b == y.B) ? y.C : secEnd;
for
(
byte
c = cStart; c <= cEnd; c++)
{
byte
dStart = (a == x.A && b == x.B && c == x.C) ? x.D : secStart;
byte
dEnd = (a == y.A && b == y.B && c == y.C) ? y.D : secEnd;
for
(
byte
d = dStart; d <= dEnd; d++)
{
OutputIpAddress(a, b, c, d);
}
//这个是测试用的,只输出这一网段最后一位的起止位置,不输出全部。
//Output("========输出网段========");
//OutputIpAddress(a, b, c, dStart);
//OutputIpAddress(a, b, c, dEnd);
}
}
}
}
========================
string
ipStr1 =
"1.1.1.1"
;
string
ipStr2 =
"1.1.2.2"
;
string
[] ipArray1 = ipStr1.Split(
new
char
[] {
'.'
});
string
[] ipArray2 = ipStr2.Split(
new
char
[] {
'.'
});
long
ipStart = 256 * 256 * 256 *
long
.Parse(ipArray1[0]) + 256 * 256 *
long
.Parse(ipArray1[1]) + 256 *
long
.Parse(ipArray1[2]) +
long
.Parse(ipArray1[3]);
long
ipEnd = 256 * 256 * 256 *
long
.Parse(ipArray2[0]) + 256 * 256 *
long
.Parse(ipArray2[1]) + 256 *
long
.Parse(ipArray2[2]) +
long
.Parse(ipArray2[3]);
List<
string
> SearchIPArray =
new
List<
string
>();
//存放你的中间IP
for
(
long
i = ipStart; i <= ipEnd; i++)
{
long
tmp = i;
long
a = tmp / (256 * 256 * 256);
tmp -= a * (256 * 256 * 256);
long
b = tmp / (256 * 256);
tmp -= b * 256 * 256;
long
c = tmp / 256;
tmp -= c * 256;
long
d = tmp;
SearchIPArray.Add(a.ToString() +
"."
+ b.ToString() +
"."
+ c.ToString() +
"."
+ d.ToString());
}
循环ip段 转载 出处不明的更多相关文章
- 【转载】IIS6、IIS7、IIS7.5设置拒绝一组计算机(IP段)访问网站的方法
IIS6设置方法: 1.打开IIS管理器,右键点击网站,选择“属性” 2.把标签切换到“目录安全性”,点击“IP地址和域名限制”的编辑按钮,如下图: IP地址和域名限制 3.选择“授权访问”,然后点击 ...
- [转帖]IP地址、子网掩码、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?
IP地址.子网掩码.网络号.主机号.网络地址.主机地址以及ip段/数字-如192.168.0.1/24是什么意思? 2016年03月26日 23:38:50 JeanCheng 阅读数:105674 ...
- IP段,ASN与BGP之间的关系
概览 IP段就是类似于1.0.2.0-1.0.2.255或者1.0.2.0/24的形式 ASN(Autonomous system number)自治系统编号 BGP(Border Gateway P ...
- 百度蜘蛛IP段分析
大家进行网站日志分析的时候,常见到很多不同IP段的百度蜘蛛,为了方便大家更好的进行日志分析,下面列举了百度不同IP段常见蜘蛛的一些详情情况,及所谓的降权蜘蛛,沙盒蜘蛛,高权重蜘蛛等等 下面的百度蜘蛛I ...
- 一键批量ping任意ip段的存活主机
=======================by me===================================== @echo offecho.color FC for /f %%i ...
- linux编写脚本检测本机链接指定IP段是否畅通
linux编写脚本检测本机链接指定IP段是否畅通,通过ping命令检测指定IP,检测命令执行结果,若为0表示畅通,若为1表示不通,以此判断网络是否畅通,但是指定机器禁用ping命令除外.代码如下: # ...
- bootargs中ip段各项解释
目标板:合众达的SEED-DVS6467开发板 内核版本:2.6.10 最近同事测试板卡nfs挂载PC的文件系统时出现点问题,PC上ifconfig中显示以太网为eth3,然而板卡启动参数列表相关信息 ...
- ip效验和ip段的效验
package com.juchen.utils; import javax.servlet.http.HttpServletRequest; /** * ip 相关的工具方法 */ public ...
- [转帖]Oracle 使用sqlnet.ora/trigger限制/允许某IP或IP段访问指定用户
Oracle 使用sqlnet.ora/trigger限制/允许某IP或IP段访问指定用户 原创 Oracle 作者:maohaiqing0304 时间:2016-05-03 17:05:46 17 ...
随机推荐
- XPath相关笔记
<?xml version="1.0" encoding="utf-8" ?> <employees> <employee o ...
- fragment类onresume里面刷新操作处理
今天项目中涉及fragment中嵌套多个fragment,但是要根据tag去展示对应的fragment,而不是默认展示的第一个fragment,如果使用activity很容易想到onpause(),o ...
- 第七十四节,css边框与背景
css边框与背景 学习要点: 1.声明边框 2.边框样式 3.圆角边框 本章主要探讨HTML5中CSS边框和背景,通过边框和背景的样式设置,给元素增加更丰富的外观. 声明边框 边框的声明有三个属性设 ...
- FZU 1502 Letter Deletion(DP)
Description You are given two words (each word consists of upper-case English letters). Try to delet ...
- 在一个页面重复使用一个js函数的方法
给每个拥有相同行为的问题DOM节点一个相同的class类,如question,同时给不同的问题一个不同的标识ID如 id="question1" id="question ...
- openwrt 路由器变砖后修复方法
https://wiki.openwrt.org/doc/howto/generic.debrick 变砖后需根据类型进行修复,主要有以下四种: (1)if only something on the ...
- LeetCode OJ 34. Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value. You ...
- MySQL 的一个Bug?
在 my.ini 中的 [mysqld] 段设置 mysql basedir 和 datadir,如下: #Path to installation directory. All paths are ...
- IntelliJ IDEA 13.1.4新建java web项目
打开软件
- 【入门一】一些简单的C程序及VS的安装
实例1 用 printf 函数打印字符串 # include <stdio.h> // 预处理指令,结尾不加 ';' int main(void) // int表示该函数将返回一个整数值, ...