lua 随机生成 中国大陆 ip

用来给 nmap 进行对中国范围 Ip 的随机扫描
bit={data32={2147483648,1073741824,536870912,268435456,134217728,67108864,33554432,16777216,8388608,4194304,2097152,1048576,524288,262144,131072,65536,32768,16384,8192,4096,2048,1024,512,256,128,64,32,16,8,4,2,1}}

function bit:d2b(arg)
	local   tr={}
	for i=1,32 do
		if arg >= self.data32[i] then
		tr[i]=1
		arg=arg-self.data32[i]
		else
		tr[i]=0
		end
	end
	return   tr
end   --bit:d2b

function    bit:b2d(arg)
	local   nr=0
	for i=1,32 do
		if arg[i] ==1 then
		nr=nr+2^(32-i)
		end
	end
	return  nr
end   --bit:b2d

function    bit:_xor(a,b)
	local   op1=self:d2b(a)
	local   op2=self:d2b(b)
	local   r={}

	for i=1,32 do
		if op1[i]==op2[i] then
			r[i]=0
		else
			r[i]=1
		end
	end
	return  self:b2d(r)
end --bit:xor

function    bit:_and(a,b)
	local   op1=self:d2b(a)
	local   op2=self:d2b(b)
	local   r={}

	for i=1,32 do
		if op1[i]==1 and op2[i]==1  then
			r[i]=1
		else
			r[i]=0
		end
	end
	return  self:b2d(r)

end --bit:_and

function    bit:_or(a,b)
	local   op1=self:d2b(a)
	local   op2=self:d2b(b)
	local   r={}

	for i=1,32 do
		if  op1[i]==1 or   op2[i]==1   then
			r[i]=1
		else
			r[i]=0
		end
	end
	return  self:b2d(r)
end --bit:_or

function    bit:_not(a)
	local   op1=self:d2b(a)
	local   r={}

	for i=1,32 do
		if  op1[i]==1   then
			r[i]=0
		else
			r[i]=1
		end
	end
	return  self:b2d(r)
end --bit:_not

function    bit:_rshift(a,n)
	local   op1=self:d2b(a)
	local   r=self:d2b(0)

	if n < 32 and n > 0 then
		for i=1,n do
			for i=31,1,-1 do
				op1[i+1]=op1[i]
			end
			op1[1]=0
		end
	r=op1
	end
	return  self:b2d(r)
end --bit:_rshift

function    bit:_lshift(a,n)
	local   op1=self:d2b(a)
	local   r=self:d2b(0)

	if n < 32 and n > 0 then
		for i=1,n   do
			for i=1,31 do
				op1[i]=op1[i+1]
			end
			op1[32]=0
		end
	r=op1
	end
	return  self:b2d(r)
end --bit:_lshift


function    bit:print(ta)
	local   sr=""
	for i=1,32 do
		sr=sr..ta[i]
	end
	print(sr)
end




local ips = {{"47.153.128.0","47.154.255.255"},
{"58.14.0.0","58.25.255.255"},
{"58.30.0.0","58.63.255.255"},
{"58.66.0.0","58.68.255.255"},
{"58.82.0.0","58.83.255.255"},
{"58.87.64.0","58.87.127.255"},
{"58.99.128.0","58.101.255.255"},
{"58.116.0.0","58.119.255.255"},
{"58.128.0.0","58.135.255.255"},
{"58.144.0.0","58.144.255.255"},
{"58.154.0.0","58.155.255.255"},
{"58.192.0.0","58.223.255.255"},
{"58.240.0.0","58.255.255.255"},
{"59.32.0.0","59.65.255.255"},
{"59.67.0.0","59.83.255.255"},
{"59.107.0.0","59.111.255.255"},
{"59.151.0.0","59.151.127.255"},
{"59.155.0.0","59.155.255.255"},
{"59.172.0.0","59.175.255.255"},
{"59.191.0.0","59.201.255.255"},
{"59.201.255.255","59.211.255.255"},
{"59.211.255.255","59.221.255.255"},
{"59.221.255.255","59.231.255.255"},
{"59.231.255.255","59.241.255.255"},
{"59.241.255.255","59.251.255.255"},
{"59.251.255.255","59.255.255.255"},
{"60.0.0.0","60.11.255.255"},
{"60.11.255.255","60.21.255.255"},
{"60.21.255.255","60.31.255.255"},
{"60.55.0.0","60.55.255.255"},
{"60.63.0.0","60.63.255.255"},
{"60.160.0.0","60.171.255.255"},
{"60.171.255.255","60.181.255.255"},
{"60.181.255.255","60.191.255.255"},
{"60.194.0.0","60.195.255.255"},
{"60.200.0.0","60.223.255.255"},
{"60.232.0.0","60.233.255.255"},
{"60.235.0.0","60.235.255.255"},
{"60.245.128.0","60.245.255.255"},
{"60.247.0.0","60.247.255.255"},
{"60.252.0.0","60.253.255.255"},
{"60.255.0.0","60.255.255.255"},
{"61.4.64.0","61.4.191.255"},
{"61.8.160.0","61.8.175.255"},
{"61.26.103.0","61.26.103.255"},
{"61.28.0.0","61.29.255.255"},
{"61.45.128.0","61.45.191.255"},
{"61.47.128.0","61.55.255.255"},
{"61.87.192.0","61.87.255.255"},
{"61.128.0.0","61.131.255.255"},
{"61.131.255.255","61.141.255.255"},
{"61.141.255.255","61.151.255.255"},
{"61.151.255.255","61.161.255.255"},
{"61.161.255.255","61.171.255.255"},
{"61.171.255.255","61.181.255.255"},
{"61.181.255.255","61.191.255.255"},
{"61.232.0.0","61.237.255.255"},
{"61.240.0.0","61.243.255.255"},
{"80.227.196.0","80.227.196.255"},
{"116.1.0.0","116.11.255.255"},
{"116.13.0.0","116.13.255.255"},
{"116.16.0.0","116.23.255.255"},
{"116.23.255.255","116.31.255.255"},
{"116.52.0.0","116.58.223.255"},
{"116.60.0.0","116.63.255.255"},
{"116.66.0.0","116.66.127.255"},
{"116.69.0.0","116.70.127.255"},
{"116.76.0.0","116.79.255.255"},
{"116.89.144.0","116.90.191.255"},
{"116.95.0.0","116.95.255.255"},
{"116.112.0.0","116.117.255.255"},
{"116.128.0.0","116.135.255.255"},
{"116.135.255.255","116.145.255.255"},
{"116.145.255.255","116.155.255.255"},
{"116.155.255.255","116.165.255.255"},
{"116.165.255.255","116.175.255.255"},
{"116.175.255.255","116.185.255.255"},
{"116.185.255.255","116.195.255.255"},
{"116.198.0.0","116.199.159.255"},
{"116.204.0.0","116.205.255.255"},
{"116.207.0.0","116.219.255.255"},
{"116.224.0.0","116.239.255.255"},
{"116.242.0.0","116.249.255.255"},
{"116.252.0.0","116.255.255.255"},
{"117.8.0.0","117.15.255.255"},
{"117.21.0.0","117.45.255.255"},
{"117.48.0.0","117.51.255.255"},
{"117.53.48.0","117.53.191.255"},
{"117.57.0.0","117.95.255.255"},
{"117.100.0.0","117.101.255.255"},
{"117.103.16.0","117.103.143.255"},
{"117.106.0.0","117.107.255.255"},
{"117.112.0.0","117.191.255.255"},
{"118.21.0.0","118.21.255.255"},
{"118.24.0.0","118.26.255.255"},
{"118.45.36.0","118.45.36.255"},
{"118.72.0.0","118.79.255.255"},
{"118.81.0.0","118.81.255.255"},
{"118.84.0.0","118.84.255.255"},
{"118.88.0.0","118.88.255.255"},
{"118.91.0.0","118.91.255.255"},
{"118.112.0.0","118.126.255.255"},
{"118.144.0.0","118.147.255.255"},
{"118.192.0.0","118.192.127.255"},
{"118.197.0.0","118.197.255.255"},
{"118.205.0.0","118.205.255.255"},
{"118.212.0.0","118.229.219.255"},
{"118.244.0.0","118.245.255.255"},
{"118.248.0.0","118.249.255.255"},
{"119.0.0.0","119.5.255.255"},
{"119.12.0.0","119.12.255.255"},
{"119.18.0.0","119.23.255.255"},
{"119.32.20.0","119.32.63.255"},
{"119.36.0.0","119.36.255.255"},
{"119.38.0.0","119.40.255.255"},
{"119.45.192.0","119.45.255.255"},
{"119.48.0.0","119.48.255.255"},
{"119.81.0.0","119.81.255.255"},
{"119.96.0.0","119.96.255.255"},
{"119.112.0.0","119.127.98.255"},
{"119.127.98.255","119.137.98.255"},
{"119.137.98.255","119.147.98.255"},
{"119.161.0.0","119.161.255.255"},
{"119.167.0.0","119.167.255.255"},
{"120.0.0.0","120.7.255.255"},
{"120.32.0.0","120.39.255.255"},
{"120.48.0.0","120.48.255.255"},
{"120.64.0.0","120.67.255.255"},
{"120.87.201.0","120.87.201.255"},
{"121.0.16.0","121.0.31.255"},
{"121.4.0.0","121.5.255.255"},
{"121.8.0.0","121.43.255.255"},
{"121.46.0.0","121.49.255.255"},
{"121.51.0.0","121.52.255.255"},
{"121.55.0.0","121.63.255.255"},
{"121.68.0.0","121.71.255.255"},
{"121.76.0.0","121.77.255.255"},
{"121.79.128.0","121.79.191.255"},
{"121.89.0.0","121.89.255.255"},
{"121.100.128.0","121.101.223.255"},
{"121.192.0.0","121.199.255.255"},
{"121.201.0.0","121.201.255.255"},
{"121.204.0.0","121.207.255.255"},
{"121.224.0.0","121.239.255.255"},
{"121.248.0.0","121.251.255.255"},
{"121.255.0.0","121.255.255.255"},
{"122.0.64.0","122.0.255.255"},
{"122.4.0.0","122.15.255.255"},
{"122.17.64.0","122.17.127.255"},
{"122.48.0.0","122.49.63.255"},
{"122.51.0.0","122.51.255.255"},
{"122.64.0.0","122.97.255.255"},
{"122.102.0.0","122.102.95.255"},
{"122.112.0.0","122.115.255.255"},
{"122.136.0.0","122.144.255.255"},
{"122.152.192.0","122.152.255.255"},
{"122.156.0.0","122.159.255.255"},
{"122.186.0.0","122.186.255.255"},
{"122.192.0.0","122.195.255.255"},
{"122.198.0.0","122.198.255.255"},
{"122.200.64.0","122.200.127.255"},
{"122.204.0.0","122.207.255.255"},
{"122.224.0.0","122.248.63.255"},
{"123.0.128.0","123.0.191.255"},
{"123.4.0.0","123.15.255.255"},
{"123.49.128.0","123.49.255.255"},
{"123.52.0.0","123.101.255.255"},
{"123.103.0.0","123.103.127.255"},
{"123.108.128.0","123.108.223.255"},
{"123.112.0.0","123.139.255.255"},
{"123.144.0.0","123.175.255.255"},
{"123.177.0.0","123.191.255.255"},
{"123.196.0.0","123.197.255.255"},
{"123.199.128.0","123.199.255.255"},
{"123.206.0.0","123.207.255.255"},
{"123.232.0.0","123.235.255.255"},
{"123.242.0.0","123.242.127.255"},
{"123.244.0.0","123.247.255.255"},
{"123.249.0.0","123.249.255.255"},
{"123.253.0.0","123.253.255.255"},
{"124.6.64.0","124.6.127.255"},
{"124.14.0.0","124.17.255.255"},
{"124.20.0.0","124.23.255.255"},
{"124.28.192.0","124.29.127.255"},
{"124.31.0.0","124.31.255.255"},
{"124.40.112.0","124.40.191.255"},
{"124.42.0.0","124.42.255.255"},
{"124.47.0.0","124.47.63.255"},
{"124.64.0.0","124.79.255.255"},
{"124.88.0.0","124.95.255.255"},
{"124.108.8.0","124.108.47.255"},
{"124.112.0.0","124.119.255.255"},
{"124.126.0.0","124.135.255.255"},
{"124.147.128.0","124.147.255.255"},
{"124.156.0.0","124.156.255.255"},
{"124.160.0.0","124.167.255.255"},
{"124.172.0.0","124.175.255.255"},
{"124.192.0.0","124.193.255.255"},
{"124.196.0.0","124.196.255.255"},
{"124.200.0.0","124.207.255.255"},
{"124.220.0.0","124.240.191.255"},
{"124.242.0.0","124.243.255.255"},
{"124.248.0.0","124.251.255.255"},
{"124.254.0.0","124.254.63.255"},
{"125.31.192.0","125.47.255.255"},
{"125.58.128.0","125.58.255.255"},
{"125.61.128.0","125.62.63.255"},
{"125.64.0.0","125.98.255.255"},
{"125.104.0.0","125.127.255.255"},
{"125.169.0.0","125.169.255.255"},
{"125.171.0.0","125.171.255.255"},
{"125.208.0.0","125.208.63.255"},
{"125.210.0.0","125.211.255.255"},
{"125.213.0.0","125.223.255.255"},
{"125.254.128.0","125.254.255.255"},
{"132.246.27.0","132.246.27.255"},
{"147.243.224.0","147.243.255.255"},
{"159.226.0.0","159.226.255.255"},
{"161.207.0.0","161.207.255.255"},
{"162.105.0.0","162.105.255.255"},
{"167.139.0.0","167.139.255.255"},
{"168.160.0.0","168.160.255.255"},
{"192.188.170.0","192.188.170.255"},
{"192.192.9.0","192.192.78.255"},
{"194.54.88.32","194.54.88.47"},
{"194.117.101.45","194.117.119.101"},
{"195.112.167.20","195.112.177.127"},
{"199.64.0.0","199.64.0.255"},
{"202.0.110.0","202.0.110.255"},
{"202.3.77.0","202.4.255.255"},
{"202.8.128.0","202.8.159.255"},
{"202.10.64.0","202.12.19.255"},
{"202.14.88.0","202.14.238.255"},
{"202.20.120.0","202.20.120.255"},
{"202.22.248.0","202.22.255.255"},
{"202.38.0.0","202.38.191.255"},
{"202.41.142.0","202.41.255.255"},
{"202.43.144.0","202.43.159.255"},
{"202.46.224.0","202.46.239.255"},
{"202.60.112.0","202.60.127.255"},
{"202.63.248.0","202.63.251.255"},
{"202.69.16.0","202.70.31.255"},
{"202.74.8.0","202.76.240.255"},
{"202.85.208.0","202.85.223.255"},
{"202.90.0.0","202.104.27.255"},
{"202.104.27.255","202.114.27.255"},
{"202.114.27.255","202.124.27.255"},
{"202.127.0.0","202.127.255.255"},
{"202.130.0.0","202.131.223.255"},
{"202.136.48.0","202.136.255.255"},
{"202.141.160.0","202.143.31.255"},
{"202.148.96.0","202.150.31.255"},
{"202.152.176.0","202.153.63.255"},
{"202.158.160.0","202.158.200.255"},
{"202.160.168.0","202.160.191.255"},
{"202.164.0.0","202.168.190.255"},
{"202.170.216.0","202.170.224.255"},
{"202.173.8.0","202.173.255.255"},
{"202.179.240.0","202.181.127.255"},
{"202.189.80.0","202.189.95.255"},
{"202.192.0.0","202.207.255.255"},
{"202.234.0.0","202.234.255.255"},
{"203.79.0.0","203.81.31.255"},
{"203.83.56.0","203.83.63.255"},
{"203.86.0.0","203.95.111.255"},
{"203.99.80.0","203.100.207.255"},
{"203.110.160.0","203.110.191.255"},
{"203.112.80.0","203.112.95.255"},
{"203.118.192.0","203.119.35.255"},
{"203.128.96.0","203.128.159.255"},
{"203.130.32.0","203.130.63.255"},
{"203.132.32.0","203.132.63.255"},
{"203.134.240.0","203.135.175.255"},
{"203.148.0.0","203.148.63.255"},
{"203.152.64.0","203.152.95.255"},
{"203.156.192.0","203.156.255.255"},
{"203.158.16.0","203.158.23.255"},
{"203.160.64.0","203.161.223.255"},
{"203.163.73.0","203.163.73.255"},
{"203.166.160.0","203.166.191.255"},
{"203.171.224.0","203.171.239.255"},
{"203.174.7.0","203.176.175.255"},
{"203.184.80.0","203.184.95.255"},
{"203.187.160.0","203.187.191.255"},
{"203.190.96.0","203.192.31.255"},
{"203.196.0.0","203.196.7.255"},
{"203.207.64.0","203.209.255.255"},
{"203.212.0.0","203.212.95.255"},
{"210.2.0.0","210.2.31.255"},
{"210.5.0.0","210.5.159.255"},
{"210.12.0.0","210.16.191.255"},
{"210.21.0.0","210.23.32.255"},
{"210.25.0.0","210.37.255.255"},
{"210.37.255.255","210.47.255.255"},
{"210.51.0.0","210.53.255.255"},
{"210.56.80.23","210.56.223.255"},
{"210.72.0.0","210.79.255.255"},
{"210.82.0.0","210.83.255.255"},
{"210.87.128.0","210.87.191.255"},
{"210.144.136.0","210.144.142.255"},
{"210.156.110.0","210.156.110.255"},
{"210.166.2.0","210.166.2.255"},
{"210.168.1.0","210.168.71.255"},
{"210.185.192.0","210.186.24.255"},
{"210.192.96.0","210.192.127.255"},
{"210.210.159.0","210.211.15.255"},
{"211.64.0.0","211.71.255.255"},
{"211.80.0.0","211.93.255.255"},
{"211.93.255.255","211.103.255.255"},
{"211.136.0.0","211.147.255.255"},
{"211.147.255.255","211.157.255.255"},
{"212.63.181.28","212.63.181.79"},
{"218.0.0.0","218.11.255.255"},
{"218.11.255.255","218.21.255.255"},
{"218.21.255.255","218.31.255.255"},
{"218.56.0.0","218.69.255.255"},
{"218.69.255.255","218.79.255.255"},
{"218.79.255.255","218.89.255.255"},
{"218.89.255.255","218.99.255.255"},
{"218.104.0.0","218.109.255.255"},
{"218.185.192.0","218.185.223.255"},
{"218.192.0.0","218.207.255.255"},
{"218.240.0.0","218.247.255.255"},
{"218.249.0.0","218.249.255.255"},
{"219.72.0.0","219.72.255.255"},
{"219.82.0.0","219.82.255.255"},
{"219.128.0.0","219.139.255.255"},
{"219.139.255.255","219.149.255.255"},
{"219.216.0.0","219.225.255.255"},
{"219.225.255.255","219.239.255.255"},
{"219.242.0.0","219.247.255.255"},
{"220.101.192.0","220.101.255.255"},
{"220.112.0.0","220.115.255.255"},
{"220.152.128.0","220.152.255.255"},
{"220.154.0.0","220.155.255.255"},
{"220.159.242.0","220.167.255.255"},
{"220.167.255.255","220.177.255.255"},
{"220.177.255.255","220.187.255.255"},
{"220.187.255.255","220.197.255.255"},
{"220.197.255.255","220.207.255.255"},
{"220.231.0.0","220.232.127.255"},
{"220.234.0.0","220.234.255.255"},
{"220.242.0.0","220.243.255.255"},
{"220.248.0.0","220.252.255.255"},
{"221.0.0.0","221.15.255.255"},
{"221.122.0.0","221.123.255.255"},
{"221.129.0.0","221.131.255.255"},
{"221.133.224.0","221.133.255.255"},
{"221.136.0.0","221.137.255.255"},
{"221.172.0.0","221.183.255.255"},
{"221.192.0.0","221.202.255.255"},
{"221.202.255.255","221.212.255.255"},
{"221.212.255.255","221.222.255.255"},
{"221.222.255.255","221.239.255.255"},
{"222.15.56.0","222.25.255.255"},
{"222.25.255.255","222.35.255.255"},
{"222.25.255.255","222.45.255.255"},
{"222.45.255.255","222.55.255.255"},
{"222.55.255.255","222.65.255.255"},
{"222.65.255.255","222.75.255.255"},
{"222.75.255.255","222.85.255.255"},
{"222.85.255.255","222.95.255.255"},
{"222.125.0.0","222.126.255.255"},
{"222.128.0.0","222.143.255.255"},
{"222.160.0.0","222.163.255.255"},
{"222.167.134.0","222.223.255.255"},
{"222.240.0.0","222.249.255.255"},
{"58.32.0.0","58.63.161.255"},
{"58.155.148.0","58.155.151.255"},
{"58.208.0.0","58.223.255.255"},
{"58.246.242.0","58.246.250.255"},
{"59.32.0.0","59.63.231.255"},
{"59.172.0.0","59.175.255.255"},
{"60.21.212.9","60.21.212.23"},
{"60.29.11.0","60.29.11.255"},
{"60.160.0.0","60.191.255.255"},
{"60.194.0.0","60.195.255.255"},
{"60.235.0.0","60.235.255.255"},
{"61.49.121.0","61.51.125.255"},
{"61.128.0.0","61.134.95.255"},
{"61.136.64.0","61.147.255.255"},
{"61.150.0.0","61.161.127.255"},
{"61.164.0.0","61.167.27.30"},
{"61.169.0.0","61.175.255.255"},
{"61.177.0.0","61.191.255.255"},
{"61.232.235.0","61.232.235.255"},
{"61.235.21.0","61.236.68.255"},
{"61.241.181.142","61.241.231.75"},
{"116.1.0.0","116.1.255.255"},
{"116.4.0.0","116.11.255.255"},
{"116.16.0.0","116.31.255.255"},
{"116.52.0.0","116.55.255.255"},
{"116.70.49.0","116.70.49.255"},
{"116.192.0.0","116.192.255.255"},
{"116.207.0.0","116.212.175.255"},
{"116.215.14.0","116.215.26.255"},
{"116.224.0.0","116.239.255.255"},
{"116.242.0.0","116.243.255.255"},
{"116.246.0.0","116.249.255.255"},
{"116.252.0.0","116.253.255.255"},
{"117.21.0.0","117.45.255.255"},
{"117.57.0.0","117.57.255.255"},
{"117.60.0.0","117.71.255.255"},
{"117.79.144.0","117.95.255.255"},
{"118.45.36.0","118.45.36.255"},
{"118.112.0.0","118.125.255.255"},
{"118.213.0.0","118.213.255.255"},
{"118.248.0.0","118.249.255.255"},
{"119.0.0.0","119.1.255.255"},
{"119.39.25.0","119.39.25.255"},
{"119.45.255.0","119.45.255.255"},
{"119.96.0.0","119.96.255.255"},
{"119.120.0.0","119.147.98.255"},
{"120.34.64.0","120.39.255.255"},
{"121.8.0.0","121.15.255.255"},
{"121.32.0.0","121.35.255.255"},
{"121.56.0.0","121.63.255.255"},
{"121.68.191.0","121.68.191.255"},
{"121.204.0.0","121.207.255.255"},
{"121.224.0.0","121.239.255.255"},
{"122.4.0.0","122.7.255.255"},
{"122.11.62.0","122.11.62.255"},
{"122.102.80.0","122.102.95.255"},
{"122.186.0.0","122.186.255.255"},
{"122.224.0.0","122.247.255.255"},
{"123.52.0.0","123.55.255.255"},
{"123.96.169.0","123.97.255.255"},
{"123.101.0.0","123.101.255.255"},
{"123.160.0.0","123.175.255.255"},
{"123.177.0.0","123.177.255.255"},
{"123.180.0.0","123.187.255.255"},
{"123.244.0.0","123.247.255.255"},
{"123.253.76.0","123.253.126.255"},
{"124.31.0.0","124.31.255.255"},
{"124.68.192.0","124.68.192.255"},
{"124.72.0.0","124.79.255.255"},
{"124.112.0.0","124.119.255.255"},
{"124.126.0.0","124.126.63.255"},
{"124.192.0.0","124.193.255.255"},
{"124.202.0.0","124.207.255.255"},
{"124.224.0.0","124.240.104.255"},
{"124.243.201.0","124.243.201.255"},
{"125.64.0.0","125.95.255.255"},
{"125.104.0.0","125.127.255.255"},
{"202.38.32.0","202.38.174.255"},
{"202.75.208.0","202.75.223.255"},
{"202.96.18.0","202.105.255.255"},
{"202.107.128.0","202.107.255.255"},
{"202.109.0.0","202.111.255.255"},
{"202.120.37.0","202.120.39.248"},
{"202.167.235.128","202.167.236.255"},
{"202.173.224.0","202.173.255.255"},
{"202.199.212.0","202.199.215.255"},
{"202.205.234.0","202.205.235.255"},
{"203.93.50.0","203.93.50.255"},
{"210.5.128.0","210.5.143.255"},
{"210.13.255.0","210.13.255.255"},
{"210.22.45.0","210.22.45.255"},
{"210.51.228.230","210.52.61.255"},
{"210.75.96.0","210.75.105.1"},
{"210.77.32.0","210.77.63.255"},
{"210.168.1.0","210.168.71.255"},
{"211.67.66.0","211.68.70.255"},
{"211.100.209.169","211.101.127.255"},
{"211.103.128.0","211.103.255.255"},
{"211.145.197.0","211.145.197.255"},
{"211.147.0.0","211.148.159.255"},
{"211.152.50.0","211.152.57.255"},
{"211.154.8.131","211.156.30.255"},
{"211.158.11.0","211.158.11.11"},
{"211.162.80.0","211.162.81.255"},
{"211.167.233.0","211.167.255.255"},
{"218.0.0.0","218.6.255.255"},
{"218.8.190.105","218.11.246.255"},
{"218.13.0.0","218.24.6.255"},
{"218.26.231.162","218.31.255.255"},
{"218.56.0.0","218.56.2.255"},
{"218.58.6.0","218.59.126.255"},
{"218.61.32.0","218.67.127.255"},
{"218.69.215.245","218.97.248.255"},
{"218.104.223.0","218.104.223.255"},
{"218.106.156.0","218.106.156.255"},
{"218.200.153.0","218.201.229.255"},
{"218.204.75.0","218.204.75.255"},
{"218.241.64.0","218.241.255.255"},
{"218.244.62.0","218.244.255.255"},
{"218.246.160.0","218.247.255.255"},
{"218.249.0.0","218.249.255.255"},
{"219.72.235.0","219.72.236.255"},
{"219.128.0.0","219.154.94.28"},
{"219.159.51.161","219.159.254.255"},
{"219.234.128.0","219.235.63.255"},
{"219.238.0.192","219.239.255.255"},
{"219.243.140.0","219.243.140.255"},
{"220.154.230.0","220.154.230.255"},
{"220.160.0.0","220.191.239.255"},
{"220.250.12.0","220.250.12.255"},
{"221.7.62.0","221.7.62.255"},
{"221.14.243.0","221.14.243.255"},
{"221.136.214.3","221.136.219.181"},
{"221.224.0.0","221.239.255.255"},
{"222.15.59.0","222.15.59.255"},
{"222.35.12.0","222.36.76.255"},
{"222.39.112.13","222.39.112.16"},
{"222.64.0.0","222.95.255.255"},
{"222.132.112.0","222.132.127.255"},
{"222.141.207.0","222.141.207.255"},
{"222.168.0.0","222.191.255.255"},
{"222.199.146.0","222.199.146.255"},
{"222.208.0.0","222.223.240.255"},
{"222.240.0.0","222.247.255.255"},
{"58.66.0.0","58.67.255.255"},
{"58.82.0.0","58.83.255.255"},
{"58.252.146.0","58.253.31.255"},
{"59.46.48.0","59.46.172.255"},
{"59.49.12.40","59.49.127.255"},
{"59.53.52.0","59.54.127.255"},
{"59.63.160.0","59.63.255.255"},
{"59.107.57.0","59.107.127.255"},
{"59.110.0.0","59.111.180.255"},
{"59.151.48.0","59.151.53.255"},
{"59.155.0.0","59.155.255.255"},
{"59.191.0.0","59.191.127.255"},
{"60.2.89.0","60.2.89.255"},
{"60.30.96.0","60.30.142.255"},
{"60.179.136.0","60.179.136.255"},
{"60.190.238.161","60.190.238.178"},
{"60.204.128.0","60.205.255.255"},
{"60.233.150.0","60.233.150.255"},
{"61.29.241.0","61.29.255.255"},
{"61.136.122.0","61.136.123.255"},
{"61.142.111.105","61.142.247.154"},
{"61.163.210.247","61.163.245.255"},
{"61.178.237.0","61.178.237.255"},
{"61.185.237.120","61.185.238.251"},
{"61.187.7.200","61.187.8.255"},
{"61.232.0.0","61.237.255.255"},
{"61.240.191.0","61.241.252.255"},
{"116.52.2.177","116.52.2.189"},
{"116.60.0.0","116.63.225.255"},
{"116.194.0.0","116.194.255.255"},
{"116.204.0.0","116.205.255.255"},
{"116.215.67.0","116.217.231.255"},
{"116.244.37.0","116.244.127.255"},
{"116.254.128.0","116.254.199.255"},
{"117.45.224.0","117.45.247.255"},
{"117.48.44.0","117.48.235.255"},
{"117.51.0.0","117.51.255.255"},
{"117.75.0.0","117.76.247.255"},
{"117.78.0.0","117.79.151.255"},
{"117.101.128.0","117.101.128.255"},
{"117.121.0.0","117.126.255.255"},
{"117.147.0.0","117.147.255.255"},
{"118.24.193.0","118.26.255.255"},
{"118.126.65.0","118.126.66.255"},
{"118.147.48.0","118.147.255.255"},
{"118.192.0.0","118.192.127.255"},
{"118.205.0.0","118.205.255.255"},
{"118.244.64.0","118.245.66.255"},
{"119.3.0.0","119.3.22.255"},
{"119.20.40.0","119.20.40.255"},
{"119.39.254.0","119.39.254.255"},
{"119.45.192.0","119.45.192.255"},
{"119.81.128.0","119.81.128.255"},
{"120.65.0.0","120.66.49.255"},
{"121.36.20.0","121.36.247.255"},
{"121.40.0.0","121.43.255.255"},
{"121.46.0.0","121.46.250.255"},
{"121.51.0.0","121.51.255.255"},
{"121.55.0.0","121.55.50.255"},
{"121.68.0.0","121.71.127.255"},
{"121.100.128.0","121.100.255.255"},
{"121.201.0.0","121.201.191.255"},
{"122.0.128.0","122.0.255.255"},
{"122.7.52.0","122.15.143.255"},
{"122.17.64.0","122.17.127.255"},
{"122.48.0.0","122.48.199.255"},
{"122.51.64.0","122.51.98.255"},
{"122.64.0.0","122.95.255.255"},
{"122.198.0.0","122.198.63.255"},
{"122.224.166.138","122.224.187.255"},
{"123.49.128.0","123.49.255.255"},
{"123.56.0.0","123.96.168.255"},
{"123.150.0.0","123.151.14.255"},
{"123.196.0.0","123.197.121.255"},
{"123.249.0.0","123.249.207.255"},
{"123.253.76.0","123.253.203.255"},
{"124.21.192.0","124.21.255.255"},
{"124.147.128.0","124.147.255.255"},
{"124.156.0.0","124.156.255.255"},
{"124.172.0.0","124.173.243.255"},
{"124.200.0.0","124.201.255.255"},
{"124.203.183.0","124.203.247.255"},
{"124.235.128.0","124.235.128.255"},
{"124.239.193.0","124.240.98.255"},
{"124.248.0.0","124.251.255.255"},
{"125.39.0.0","125.39.0.255"},
{"125.116.166.0","125.116.171.255"},
{"125.171.160.0","125.171.195.255"},
{"125.213.0.0","125.213.127.255"},
{"125.254.128.0","125.254.191.255"},
{"202.110.98.0","202.110.98.255"},
{"202.127.116.0","202.127.119.255"},
{"202.173.8.0","202.173.15.255"},
{"203.80.144.0","203.80.159.255"},
{"203.88.222.0","203.88.223.255"},
{"203.135.119.0","203.135.119.255"},
{"210.12.91.0","210.12.100.255"},
{"210.16.128.0","210.16.189.255"},
{"210.52.80.0","210.52.80.127"},
{"210.56.192.0","210.56.223.255"},
{"210.87.140.0","210.87.144.255"},
{"211.92.172.0","211.92.175.255"},
{"211.98.0.0","211.98.255.255"},
{"211.103.16.0","211.103.24.255"},
{"211.148.64.0","211.149.255.255"},
{"211.155.96.0","211.155.127.255"},
{"218.7.129.2","218.7.129.40"},
{"218.23.163.75","218.25.77.122"},
{"218.28.13.187","218.28.131.93"},
{"218.65.208.0","218.65.211.255"},
{"218.86.6.191","218.86.6.255"},
{"218.240.28.0","218.241.63.255"},
{"219.72.228.0","219.72.229.255"},
{"219.138.11.70","219.138.45.245"},
{"219.144.162.199","219.146.197.165"},
{"219.149.236.78","219.150.190.255"},
{"220.152.128.0","220.152.191.255"},
{"220.189.92.27","220.189.92.157"},
{"220.195.8.0","220.195.8.185"},
{"220.243.103.0","220.243.119.255"},
{"220.248.229.49","220.248.229.202"},
{"221.7.208.17","221.7.208.30"},
{"221.11.99.0","221.12.190.61"},
{"221.122.128.0","221.123.128.255"},
{"221.172.0.0","221.175.255.255"},
{"221.238.169.0","221.238.179.255"},
{"222.21.224.0","222.21.224.255"},
{"222.32.0.0","222.63.255.255"},
{"222.85.83.0","222.85.126.230"},
{"222.90.71.255","222.90.208.226"},
{"222.172.224.128","222.172.224.255"},
{"222.223.53.0","222.223.255.255"},
{"58.16.0.0","58.23.255.255"},
{"58.60.3.129","58.61.31.179"},
{"58.99.190.0","58.99.191.255"},
{"58.144.0.0","58.144.255.255"},
{"58.211.124.24","58.211.229.18"},
{"58.240.0.0","58.255.255.255"},
{"59.49.16.180","59.49.19.154"},
{"59.111.12.0","59.111.32.255"},
{"60.0.0.0","60.31.255.255"},
{"60.55.0.0","60.55.255.255"},
{"60.194.14.0","60.194.192.254"},
{"60.208.0.0","60.223.255.255"},
{"61.4.64.0","61.4.79.255"},
{"61.29.146.0","61.29.147.255"},
{"61.48.0.0","61.55.255.255"},
{"61.128.210.168","61.128.210.227"},
{"61.133.0.0","61.139.177.255"},
{"61.148.0.0","61.149.255.255"},
{"61.153.13.208","61.153.13.215"},
{"61.156.0.0","61.156.255.255"},
{"61.158.0.0","61.159.63.255"},
{"61.161.0.0","61.163.255.255"},
{"61.167.0.0","61.168.255.255"},
{"61.176.0.0","61.176.255.255"},
{"61.178.152.107","61.182.255.255"},
{"61.189.0.0","61.189.166.66"},
{"61.233.7.0","61.235.139.113"},
{"61.243.201.0","61.243.201.255"},
{"116.2.0.0","116.3.255.255"},
{"116.95.0.0","116.95.255.255"},
{"116.112.0.0","116.117.255.255"},
{"116.214.240.0","116.214.240.255"},
{"116.255.128.0","116.255.255.255"},
{"117.8.0.0","117.15.255.255"},
{"117.51.17.0","117.51.17.255"},
{"118.72.0.0","118.79.255.255"},
{"118.81.0.0","118.81.255.255"},
{"118.88.0.0","118.88.63.255"},
{"118.91.0.0","118.91.255.255"},
{"118.144.144.0","118.144.144.255"},
{"118.147.0.0","118.147.47.255"},
{"118.197.0.0","118.197.255.255"},
{"118.212.0.0","118.212.255.255"},
{"119.4.0.0","119.5.217.255"},
{"119.36.0.0","119.36.255.255"},
{"119.112.0.0","119.119.255.255"},
{"119.167.0.0","119.167.255.255"},
{"120.0.0.0","120.7.255.255"},
{"120.32.0.0","120.34.63.255"},
{"121.16.0.0","121.31.255.255"},
{"121.36.160.0","121.36.160.255"},
{"121.40.216.0","121.40.220.255"},
{"121.55.51.0","121.55.63.255"},
{"122.9.56.0","122.9.56.255"},
{"122.96.0.0","122.97.255.255"},
{"122.136.0.0","122.143.255.255"},
{"122.156.0.0","122.159.255.255"},
{"122.192.0.0","122.195.255.255"},
{"123.4.0.0","123.15.255.255"},
{"123.57.127.0","123.57.127.255"},
{"123.66.6.0","123.66.6.255"},
{"123.99.128.0","123.99.255.255"},
{"123.112.0.0","123.135.255.255"},
{"123.137.0.0","123.139.255.255"},
{"123.144.0.0","123.149.255.255"},
{"123.151.15.0","123.159.255.255"},
{"123.178.0.0","123.179.255.255"},
{"123.188.0.0","123.191.255.255"},
{"123.232.0.0","123.235.255.255"},
{"123.253.96.0","123.253.127.255"},
{"124.20.80.0","124.20.80.255"},
{"124.64.0.0","124.67.255.255"},
{"124.88.0.0","124.95.255.255"},
{"124.126.130.0","124.126.130.255"},
{"124.128.0.0","124.135.255.255"},
{"124.156.112.0","124.156.112.255"},
{"124.160.0.0","124.167.255.255"},
{"125.32.0.0","125.47.255.255"},
{"125.210.0.0","125.211.255.255"},
{"202.75.211.0","202.75.211.255"},
{"202.95.18.145","202.99.244.12"},
{"202.102.9.0","202.102.254.255"},
{"202.106.0.0","202.108.255.255"},
{"202.110.0.0","202.111.189.255"},
{"202.131.22.0","202.131.22.255"},
{"202.136.252.0","202.136.255.255"},
{"202.189.80.0","202.189.80.255"},
{"203.93.9.0","203.93.255.255"},
{"203.135.96.0","203.135.127.255"},
{"203.175.128.0","203.175.255.255"},
{"203.187.188.0","203.187.188.255"},
{"203.207.98.0","203.207.98.255"},
{"203.212.8.0","203.212.8.255"},
{"210.12.0.0","210.16.191.255"},
{"210.21.0.0","210.22.255.255"},
{"210.51.0.0","210.53.255.255"},
{"210.74.94.0","210.74.159.255"},
{"210.76.32.0","210.76.159.255"},
{"210.78.17.0","210.78.26.255"},
{"210.82.0.0","210.83.255.255"},
{"210.166.2.0","210.166.2.255"},
{"211.97.245.0","211.98.125.10"},
{"211.144.175.0","211.145.94.255"},
{"211.151.0.0","211.152.60.255"},
{"211.154.0.0","211.156.191.255"},
{"211.158.0.0","211.158.255.255"},
{"211.163.0.0","211.163.255.255"},
{"218.3.91.0","218.3.91.7"},
{"218.6.48.95","218.12.255.255"},
{"218.21.127.190","218.22.122.77"},
{"218.24.8.0","218.29.255.255"},
{"218.56.8.0","218.62.127.255"},
{"218.67.128.0","218.69.255.255"},
{"218.75.22.0","218.75.22.185"},
{"218.92.207.205","218.94.70.110"},
{"218.104.0.0","218.109.255.255"},
{"218.246.33.0","218.247.21.161"},
{"219.82.0.0","219.82.255.255"},
{"219.140.69.86","219.140.255.255"},
{"219.146.142.124","219.147.99.95"},
{"219.149.94.123","219.150.15.253"},
{"219.153.130.34","219.159.161.11"},
{"219.232.208.0","219.232.255.255"},
{"219.238.108.0","219.239.128.127"},
{"220.163.127.0","220.163.159.255"},
{"220.169.200.45","220.170.75.87"},
{"220.178.48.0","220.179.173.157"},
{"220.194.197.38","220.194.202.255"},
{"220.197.189.67","220.197.226.255"},
{"220.201.35.22","220.201.59.255"},
{"220.248.0.0","220.252.255.255"},
{"221.0.0.1","221.15.255.255"},
{"221.131.219.0","221.131.219.255"},
{"221.133.228.0","221.133.232.255"},
{"221.136.0.0","221.136.255.255"},
{"221.192.0.0","221.224.114.50"},
{"221.231.10.147","221.232.91.176"},
{"222.34.101.0","222.34.101.255"},
{"222.40.40.0","222.40.43.255"},
{"222.43.101.0","222.43.101.255"},
{"222.60.160.0","222.60.164.255"},
{"222.74.42.138","222.74.168.130"},
{"222.81.42.0","222.81.42.255"},
{"222.88.60.70","222.89.16.244"},
{"222.92.61.6","222.92.95.198"},
{"222.126.190.0","222.126.190.255"},
{"222.128.0.0","222.143.255.255"},
{"222.160.0.0","222.163.255.255"},
{"222.167.134.0","222.168.73.66"},
{"222.170.96.0","222.171.22.9"},
{"222.174.50.0","222.175.23.58"}
}

math.randomseed(os.time());

function get_radom_ip()
	return math.random(0x10000000,0x7FFFFFFF)
end

function int_ip_to_str(ip)
	return string.format("%u.%u.%u.%u",(bit:_rshift(bit:_and(ip,0xFF000000) , 24)),
								(bit:_rshift(bit:_and(ip,0x00FF0000) , 16)),
								(bit:_rshift(bit:_and(ip,0x0000FF00) , 8)),
								(bit:_and(ip,0x000000FF)))
end

function str_ip_to_int(ip)
	ret = 0
	for i=1,4,1 do
		idx = string.find(ip,'.',1,true)
		if idx ~= nil then
			a = string.sub(ip,1,idx-1)
		else
			a = ip
		end
		a = a + 1
		a = a - 1
		--print(a)
		if i == 1 then
			ret = bit:_or(ret,bit:_lshift(a,24))
		elseif i == 2 then
			ret = bit:_or(ret,bit:_lshift(a,16))
		elseif i == 3 then
			ret = bit:_or(ret,bit:_lshift(a,8))
		else
			ret = bit:_or(ret,a)
		end
		if idx == nil then
			break
		end
		ip = string.sub(ip,idx+1,-1)
	end
	return ret
end


function is_ip_in_range(ip_t,ip)
	for x,v in ipairs(ip_t) do
		start_ip = v[1]
		end_ip = v[2]
		if ip >= start_ip and ip <= end_ip then
			return true
		end
	end
	return false
end

-- 把字符串 ip 表转换成整数放到一张表里
function build_ip_table()
	ip_t = {}
	for x,v in ipairs(ips) do
		start_ip = str_ip_to_int(v[1])
		end_ip = str_ip_to_int(v[2])
		if start_ip <= end_ip and start_ip > 0 then
			table.insert(ip_t,{start_ip,end_ip})
			--print('insert on..')
		else
			print("wrong ip "..v[1]..v[2])
		end
	end
	return ip_t
end

ip_t = build_ip_table()
--print(ip_t)
while true do
	i = get_radom_ip()
	if is_ip_in_range(ip_t,i) then
		print(int_ip_to_str(i))
	end
end



你可能感兴趣的:(lua,nmap)