<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS: Работа с маской подсети]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=5621&amp;type=atom" />
	<updated>2011-03-22T14:58:53Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=5621</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Работа с маской подсети]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=46575#p46575" />
			<content type="html"><![CDATA[<p><strong>MikhailSM</strong>, посмотрите на <a href="http://forum.script-coding.com/viewtopic.php?pid=29482#p29482">это</a>. Опрос производится без указания маски — маска и диапазон адресов подсети берётся по IP адресу первого подключенного сетевого адаптера.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-03-22T14:58:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=46575#p46575</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Работа с маской подсети]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=46566#p46566" />
			<content type="html"><![CDATA[<p>Нашел сам.<br /></p><div class="codebox"><pre><code>&#039;this scipt will do some very fast IP/subnet-calculations
&#039;instead of using any string-operations here like other known algorithms I am using optimized BIT-operations
&#039;carsten.giese@googlemail.com, 03.10.2010

option explicit

&#039;prepare an array for BIT-operations:
dim v,i,bit(32)
v=1
for i=0 to 31
bit(i)=NumberToLong(v)
v=v+v
next

&#039;here is a small demo how to work with the functions:

dim ip,mask,size,sn,ip1,ipN
ip=&quot;192.168.100.45&quot;
mask=&quot;255.255.255.240&quot;
sn=subnet(ip,mask)
wscript.echo &quot;subnet=&quot; &amp; IpString(sn) &amp; &quot;\&quot; &amp; maskBit(mask)
size=subnetSize(mask)
wscript.echo &quot;size =&quot; &amp; size
ip1=sn or 1
ipN=sn or size
wscript.echo &quot;first IP in subnet=&quot; &amp; IpString(ip1)
wscript.echo &quot;last IP in subnet=&quot; &amp; IpString(ipN)

wscript.echo vbCrLf &amp; &quot;sample 1: listing all IPs in subnet...&quot;
for i=ip1 to ipN
wscript.echo IpString(i)
next

wscript.echo vbCrLf &amp; &quot;sample 2:checking 65535 IPs for the same subnet...&quot;
dim a,b,o1,o2,ipVal
a=timer
for o1=0 to 255
for o2=0 to 255
ip=&quot;192.168.&quot; &amp; o1 &amp; &quot;.&quot; &amp; o2
ipVal=IpValue(ip)
if ipVal&gt;=ip1 then
if ipVal&lt;=ipN then wscript.echo ip
end if
next
next
b=timer
wscript.echo &quot;duration in seconds: &quot; &amp; b-a

&#039;---------------------------------- functions ----------------------------------
function subnetSize(mask)
&#039;returns the number of IPs for a given subnet-mask
&#039;will only work with MS/CISCO-compliant masks with leading 1-s and trailing 0-s, but not for masks like 255.0.255.0
subnetSize=-IpValue(mask)-2
end function

function subnet(IP,mask)
&#039;converts a given IP-string and subnetmask-string into a number from type LONG representing the subnet
subnet=IpValue(IP) and IpValue(mask)
end function

function IpValue(IP)
&#039;converts an IP-string into a number from type LONG (for bit-operators like AND/OR)
IpValue=NumberToLong(IpToNumber(IP))
end function

function IpToNumber(IP)
&#039;converts an IP-string into a large positive number between &amp;H00000000 and &amp;HFFFFFFFF 
dim octet
for each octet in split(IP,&quot;.&quot;)
IpToNumber=IpToNumber * 256 + CByte(octet)
next
end function

function NumberToLong(n)
&#039;converts a large number between &amp;H00000000 and &amp;HFFFFFFFF into type LONG
if n&gt;&amp;H7FFFFFFF then 
numberToLong=n-4294967296
else
numberToLong=n
end if
end function

function IpString(n)
&#039;converts a n IP-value from type LONG into a readable IP-string
dim octet,octetValue,bOffset
for octet=0 to 3
octetValue=0
for b=0 to 7
if n and bit(bOffset+b) then octetValue=octetValue + bit(b)
next
bOffset=bOffset+8
if octet=0 then
IpString=cstr(octetValue)
else
IpString= cstr(octetValue) &amp; &quot;.&quot; &amp; IpString
end if
next
end function

function maskbit(mask)
dim m,b
m = IpValue(mask)
for b=0 to 31
if (m and bit(b)) then exit for
next
maskBit=32-b
end function</code></pre></div>]]></content>
			<author>
				<name><![CDATA[MikhailSM]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26825</uri>
			</author>
			<updated>2011-03-22T14:26:24Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=46566#p46566</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBS: Работа с маской подсети]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=46565#p46565" />
			<content type="html"><![CDATA[<p>Подскажите, пожалуйста, есть ли возможность в VBS указать маску подсети к примеру /24 и сделать перебор всех айпишников циклом. С циклом понятно, а вот как сделать так чтобы скрипт менял айпишник не знаю. Алгоритм работы скрипта:<br />1. Задать маску<br />2. Посчитать какой диапозон айпишников будет и поместить их все в массив<br />3. Для каждого айпишника выполнить функцию.</p>]]></content>
			<author>
				<name><![CDATA[MikhailSM]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26825</uri>
			</author>
			<updated>2011-03-22T14:13:49Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=46565#p46565</id>
		</entry>
</feed>
