2009-07-10 4 views
0

좋아, 그건 아니,하지만 ... 그래서VBS 문자열 wizzardry

은 그래서 이것은 내 Exchange 서버에서 실행하고 나는 스팸에 수신인 확인에 사용할 수있는 전자 메일 주소 목록을 덤프 빠른 스크립트 I found on the internet입니다 필터 :

' Export all valid recipients (= proxyAddresses) into a 
' file virtual.txt 
' 
' Ferdinand Hoffmann & Patrick Koetter 
' 20021100901 
' Shamelessly stolen from 
' http://www.microsoft.com/windows2000/techinfo/ \ 
' planning/activedirectory/bulksteps.asp 


'Global variables 
Dim Container 
Dim OutPutFile 
Dim FileSystem 

'Initialize global variables 
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject") 
Set OutPutFile = FileSystem.CreateTextFile("virtual.txt", True) 
Set Container=GetObject("LDAP://CN=Users,DC=office,DC=example,DC=com") 

'Enumerate Container 
EnumerateUsers Container 

'Clean up 
OutPutFile.Close 
Set FileSystem = Nothing 
Set Container = Nothing 

'Say Finished when your done 
WScript.Echo "Finished" 
WScript.Quit(0) 

'List all Users 
Sub EnumerateUsers(Cont) 
Dim User 

'Go through all Users and select them 
For Each User In Cont 
Select Case LCase(User.Class) 

'If you find Users 
Case "user" 
    'Select all proxyAddresses 
    Dim Alias 
    If Not IsEmpty(User.proxyAddresses) Then 
    For Each Alias in User.proxyAddresses 
    OutPutFile.WriteLine "alias: " & Alias 
    'WScript.Echo Alias 
    Next 
    End If 

Case "organizationalunit" , "container" 
    EnumerateUsers User 

End Select 
Next 
End Sub 

캐치는받는 사람 목록은 다음과 같이 돌아 오는 것을 :

smtp:[email protected] 
SMTP:[email protected] 
x400:c=US;a= ;p=local;o=Exchange;s=lastname;g=firstname; 
smtp:[email protected] 
smtp:[email protected] 

스팸 필터는 "SMT와 라인을 가져 가져 오기 전대있다 p "또는"SMTP "접두어가 붙어 x400은 문제가되지 않습니다. 문제는 VBscript가 "[email protected]"주소를 내보내는 것을 원하지 않는다는 것입니다. 나는 이것을 시도했다 :

'List all Users 
Sub EnumerateUsers(Cont) 
Dim User 

'Go through all Users and select them 
For Each User In Cont 
Select Case LCase(User.Class) 

'If you find Users 
Case "user" 
    'Select all proxyAddresses 
    Dim Alias 
    If Not IsEmpty(User.proxyAddresses) Then 
    For Each Alias in User.proxyAddresses 
    If Not Alias = "*.lan" Then 
     OutPutFile.WriteLine "alias: " & Alias 
     WScript.Echo Alias 
    End If 
    Next 
    End If 

Case "organizationalunit" , "container" 
    EnumerateUsers User 

End Select 
Next 
End Sub 

그러나 그것은 아무 것도하지 않는다. 공개 도메인에 대한 일치를 시도했습니다 (Alias ​​= "publicdomain"그렇다면).하지만 결과가 나오지 않았습니다.

그래서 공개 도메인에서만 주소를 얻을 수 있도록 출력을 필터링하는 방법은 무엇입니까?

답변

0

정규식을 사용하여 기준과 일치하지 않는 행을 필터링 할 수 있습니다. 다음과 같은 것.

smtp:.*@publicdomain\.com 

또한 LDAP 쿼리를 조정하여 특정 OU의 사용자 만 반환 할 수도 있습니다. Exchange 계정이있는 사용자 만 속한 AD 그룹이 있습니까?

여기에 정규식 매칭을위한 VBS ...

Dim s : s = "smtp:[email protected]" & VBCRLF & _ 
    "SMTP:[email protected]" & VBCRLF & _ 
    "x400:c=US;a= ;p=local;o=Exchange;s=lastname;g=firstname;" & VBCRLF & _ 
    "smtp:[email protected]" & VBCRLF & _ 
    "smtp:[email protected]" 

Dim ex : ex = "smtp:.*@publicdomain\.com" 

Dim oRE: Set oRE = New RegExp 
     oRE.IgnoreCase = True 
     oRE.Global = True 
     oRE.Pattern = ex 

Dim matches : Set matches = oRE.Execute(s) 

For Each match In matches 
    WScript.Echo match.Value 
Next 
1

If Right(Alias, 4) <> ".lan" 

(그것은 정규 표현식으로 수행 할 수 있지만, 그것의 금요일에

If Not Alias = "*.lan" 

를 교체이고 나는 피곤하다!)

관련 문제