<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; VBS: Экспорт данных LDAP и конвертация Static IP Address]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=5705</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=5705&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «VBS: Экспорт данных LDAP и конвертация Static IP Address».]]></description>
		<lastBuildDate>Thu, 07 Apr 2011 12:27:42 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: VBS: Экспорт данных LDAP и конвертация Static IP Address]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=47437#p47437</link>
			<description><![CDATA[<p>Спасибо большое! Скрипт отработал без ошибок и Static IP Address отобразились в привычном формате.</p>]]></description>
			<author><![CDATA[null@example.com (NeroZyF)]]></author>
			<pubDate>Thu, 07 Apr 2011 12:27:42 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=47437#p47437</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Экспорт данных LDAP и конвертация Static IP Address]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=47429#p47429</link>
			<description><![CDATA[<div class="quotebox"><cite>NeroZyF пишет:</cite><blockquote><p>... как прикрутить её к скрипту, что бы в excel попадали правильные Static IP Address...</p></blockquote></div><p>Вероятно, перед оператором <span style="color: blue">objWSheet.Cells(intRow, intColumn).Value = strTemp</span> надо вставить конструкцию, подобную этой:<br /></p><div class="codebox"><pre><code>If StrComp(objRSet.Fields(intColumn - 1).Name, &quot;msRADIUSFramedIPAddress&quot;, vbTextCompare) = 0 Then
    If IsNumeric(strTemp) Then
        strTemp = IntegerToIPAddress(strTemp)
    End If
End If</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Dmitrii)]]></author>
			<pubDate>Thu, 07 Apr 2011 10:22:42 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=47429#p47429</guid>
		</item>
		<item>
			<title><![CDATA[VBS: Экспорт данных LDAP и конвертация Static IP Address]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=47426#p47426</link>
			<description><![CDATA[<p>Добрый день. Не могу конвертировать Static IP Address полученный при помощи скрипта. Скрипт в excel выгружает всё отлично, кроме Static IP Address, он выгружается в десятичной системе исчисления. Для конвертации Static IP Address нашел функцию. Теперь не знаю как прикрутить её к скрипту, что бы в excel попадали правильные Static IP Address. Скрипт и функция ниже.<br />Скрипт взят с Вашего форума.<br /></p><div class="codebox"><pre><code>Dim objRoot, strDomain
Dim objConnection, objCommand, objRSet
Dim objFS, objExcel, objWB, objWSheet, strBook, intRow, intColumn, strTemp
Const ADS_SCOPE_SUBTREE = 2
strBook = &quot;Users.xls&quot;
intRow = 2
Set objExcel  = CreateObject(&quot;Excel.Application&quot;)
objExcel.Visible = True
Set objWB = objExcel.Workbooks.Add
Set objWSheet = objWB.Worksheets(1)
Set objFS = CreateObject(&quot;Scripting.FileSystemObject&quot;)
strBook = objFS.BuildPath(objFS.GetParentFolderName(WScript.ScriptFullName), strBook)
Set objRoot = GetObject(&quot;LDAP://RootDSE&quot;)
strDomain = objRoot.Get(&quot;DefaultNamingContext&quot;)
Set objRoot = Nothing
Set objConnection = CreateObject(&quot;ADODB.Connection&quot;)
objConnection.Provider = &quot;ADsDSOObject&quot;
objConnection.Open &quot;Active Directory Provider&quot;
Set objCommand = CreateObject(&quot;ADODB.Command&quot;)
Set objCommand.ActiveConnection = objConnection
objCommand.Properties(&quot;Page Size&quot;) = 1000
objCommand.Properties(&quot;Timeout&quot;) = 30
objCommand.Properties(&quot;Sort On&quot;) = &quot;description&quot;
objCommand.Properties(&quot;Searchscope&quot;) = ADS_SCOPE_SUBTREE
strCommandText = _
&quot;SELECT userPrincipalName,msRADIUSFramedIPAddress FROM &#039;LDAP://&quot; _
&amp; strDomain &amp; &quot;&#039; WHERE objectCategory=&#039;Person&#039; AND objectClass=&#039;User&#039;&quot;
objCommand.CommandText = strCommandText
Set objRSet = objCommand.Execute
objRSet.MoveFirst
Do

    If intRow = 2 Then
        For intColumn = 1 To objRSet.Fields.Count
            objWSheet.Cells(intRow - 1, intColumn).Value = UCase(objRSet.Fields(intColumn - 1).Name)
        Next
    End If
    For intColumn = 1 To objRSet.Fields.Count
        strTemp = objRSet.Fields(intColumn - 1).Value
If Not IsNull(strTemp) Then
    objWSheet.Cells(intRow, intColumn).NumberFormat = &quot;@&quot;
    If IsArray(strTemp) Then
        objWSheet.Cells(intRow, intColumn).Value = Join(strTemp, vbLf)
    Else
        objWSheet.Cells(intRow, intColumn).Value = strTemp
End If
    End If
    Next
    intRow = intRow + 1
    objWSheet.Cells(intRow, 1).Activate &#039;своего рода индикатор процесса
    objRSet.MoveNext
Loop While Not objRSet.EOF
Set objRSet = Nothing
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
Set objFS = Nothing
objExcel.DisplayAlerts = False &#039;позволяет отключить запрос на выбор действия в случае,
                                             &#039;когда файл уже существует
objWSheet.Columns.AutoFit
objWB.SaveAs strBook
&#039;objWB.Close
&#039;objExcel.Quit
Set objWSheet = Nothing
Set objWB = Nothing
Set objExcel = Nothing
&#039;WScript.Echo &quot;Готово.&quot;
WScript.Quit 0</code></pre></div><p>Функция. <br /></p><div class="codebox"><pre><code>OPTION EXPLICIT
Const E_ADS_PROPERTY_NOT_FOUND  = &amp;h8000500D
DIM objUser,msRADIUSFramedIPAddress

&#039;&lt;&lt;&lt;&lt; Bind to the user object using the distinguished name &gt;&gt;&gt;&gt;
set objUser = GetObject(&quot;LDAP://cn=,ou=,ou=,ou=,dc=,dc=&quot;)

ON ERROR RESUME NEXT
msRADIUSFramedIPAddress= objUser.get(&quot;msRADIUSFramedIPAddress&quot;)

IF Err.Number = E_ADS_PROPERTY_NOT_FOUND then
    wscript.echo &quot;Static IP Address Not Assigned&quot;
    err.clear
else
    wscript.echo IntegerToIPAddress(msRADIUSFramedIPAddress)
End If

&#039; Function to convert Integer value to IP Address.
Function IntegerToIPAddress(intIP)
    Const FourthOctet = 1
    Const ThirdOctet = 256
    Const SecondOctet = 65536
    Const FirstOctet = 16777216
    dim strIP,intFirstRemainder,intSecondRemainder,intThirdRemainder
    If sgn(intIP) = -1 Then
            strIP =  (256 + (int(intIP/FirstOctet))) &amp; &quot;.&quot;
            intFirstRemainder = intIP mod FirstOctet
            strIP = strIP &amp;  (256 + (int(intFirstRemainder/SecondOctet))) &amp; &quot;.&quot;
            intSecondRemainder = intFirstRemainder mod SecondOctet
            strIP = strIP &amp; (256 + (int(intSecondRemainder/ThirdOctet))) &amp; &quot;.&quot;
               intThirdRemainder = intSecondRemainder mod ThirdOctet
            strIP = strIP &amp; (256 + (int(intThirdRemainder/FourthOctet)))
        Else
            strIP = int(intIP/FirstOctet) &amp; &quot;.&quot;
            intFirstRemainder = intIP mod FirstOctet
            strIP = strIP &amp; int(intFirstRemainder/SecondOctet) &amp; &quot;.&quot;
            intSecondRemainder = intFirstRemainder mod SecondOctet
            strIP = strIP &amp; int(intSecondRemainder/ThirdOctet) &amp; &quot;.&quot;
            intThirdRemainder = intSecondRemainder mod ThirdOctet
            strIP = strIP &amp; int(intThirdRemainder/FourthOctet)
        End If
    IntegerToIPAddress = strIP
end function</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (NeroZyF)]]></author>
			<pubDate>Thu, 07 Apr 2011 06:26:28 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=47426#p47426</guid>
		</item>
	</channel>
</rss>
