我有一个很长的IP地址列表,我需要将其作为允许的中继添加到Windows Server 2008 R2上的内置SMTP服务(IIS 7.5,但SMTP使用旧的IIS 6.0pipe理器)
我知道如何手动添加允许的继电器,但有一个很长的名单,所以我正在寻求自动化。
有没有办法从命令行,脚本或其他自动化?
IIS 6 SMTP服务器? 此configuration位于systemroot\system32\inetserv\metabase.xml中的IIS元数据库XML文件中systemroot\system32\inetserv\metabase.xml :RelayIpList
VBS设置中继IP:
Option Explicit Dim objSMTP,objRelayIpList,objCurrentList,objIP,objFSO,objTextFile,count,newIpList(),inputOption Set objSMTP = GetObject("IIS://localhost/smtpsvc/1") Set objRelayIpList = objSMTP.Get("RelayIpList") 'objRelayIpList is of type IIsIPSecuritySetting http://msdn.microsoft.com/en-us/library/ms525725.aspx Wscript.Echo "============================================" Wscript.Echo "CURRENT SETTINGS" Wscript.Echo "================" Wscript.Echo " " Wscript.Echo "Computer(s) that may relay through this virtual server." Wscript.Echo " " ' GrantByDefault returns 0 when "only the list below" is set (false) and -1 when all except the list below is set(true) If objRelayIpList.GrantByDefault = true Then Wscript.Echo "All except the list below :" objCurrentList = objRelayIpList.IPDeny Else Wscript.Echo "Only the list below :" objCurrentList = objRelayIpList.IPGrant End If count = 0 For Each objIP in objCurrentList Wscript.Echo objIP count = count + 1 Next If count = 0 Then Wscript.Echo "*NIL*" End If Wscript.Echo "============================================" Wscript.Echo " " Wscript.Echo "Replacing ReplayIpList with the IP address(es) from the ip.txt file." Wscript.Echo " " Do While Not((inputOption = "a") Or (inputOption = "d") Or (inputOption = "x") ) Wscript.Echo "ENTER " Wscript.Echo "A to add to Allow List (Only the list below)" Wscript.Echo "D to add to Deny List (All except the list below)" Wscript.Echo "X Exit without making changes" Wscript.Echo " " inputOption = lcase(trim(Wscript.StdIn.ReadLine)) Loop Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists("ip.txt") Then Set objTextFile = objFSO.OpenTextFile("ip.txt",1) count = 0 Do Until objTextFile.AtEndOfStream Redim Preserve newIpList(count) newIpList(count) = objTextFile.Readline count = count + 1 Loop objTextFile.Close 'For each objIP in newIpList ' Wscript.Echo objIP 'Next Wscript.Echo " " Select Case inputOption Case "a" objRelayIpList.GrantByDefault = false objRelayIpList.IpGrant = newIpList Wscript.Echo "SET " & count &" address(es) to Allow List" Case "d" objRelayIpList.GrantByDefault = true objRelayIpList.IpDeny = newIpList Wscript.Echo "SET " & count &" address(es) to Deny List" Case "x" Wscript.Echo "Exiting without making changes" Wscript.Echo "============================================" Wscript.Quit End Select objSMTP.Put "RelayIpList",objRelayIpList objSMTP.SetInfo Wscript.Echo " " Wscript.Echo "============================================" Else Wscript.Echo "Please create a file ip.txt that contains the list of IP address(es)" Wscript.Echo "FORMAT : Each Line should be IP,MASK " Wscript.Echo "EX : 127.0.0.1,255.255.255.255" End If
积分:
Script to Import a bunch of IP addresses to the ReplayIpList (c)[email protected] blogs.msdn.com/vijaysk USAGE : cscript ImportRelayList.vbs PREREQUISITE : This script needs ip.txt in the same folder. Store your IP addresses in ip.txt FORMAT: Each line should be IP,MASK
来自: http : //blogs.msdn.com/b/vijaysk/archive/2009/05/07/setting-smtp-relayiplist-from-a-script.aspx
未经我testing(BlueCompute)