当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 Exchange SMTP 中继查找 IP 地址

作者:精品下载站 日期:2024-12-14 22:35:19 浏览:14 分类:玩电脑

使用 Exchange SMTP 中继查找 IP 地址


您想要查找使用 Exchange SMTP 中继发送邮件的本地 IP 地址。您为什么想要获得这些信息?最常见的是,当您想要停用 Exchange Server,并且您想确认没有邮件流通过 SMTP 中继运行时。如果一切设置完毕,您可以禁用 SMTP 中继接收连接器。在本文中,您将了解如何自动搜索并查找使用 SMTP 中继的 IP 地址。

介绍

在开始之前,最好先了解一下为什么我们想知道哪些 IP 地址使用 Exchange SMTP 中继。有几个原因是当您:

  • 移动到带有 SMTP 中继的新 Exchange Server

  • 移动到 Office 365 SMTP 中继

  • 审核您可以删除哪些 IP 地址

注意:请不要立即删除 SMTP 中继接收连接器,也不要立即停用 Exchange Server。这是一个很大的错误。

我们推荐以下顺序:

  • 使用 Exchange SMTP 中继获取 IP 地址(本文)

  • 禁用 SMTP 中继接收连接器

  • 关闭 Exchange Server 一周或更长时间

  • 停用 Exchange 服务器

检查 SMTP 中继日志

要在日志中搜索 IP 地址,您需要在连接器上启用日志记录。以管理员身份运行 Exchange 命令行管理程序。运行 Get-ReceiveConnector cmdlet 并检查 SMTP 中继接收连接器上是否启用了协议日志记录。

在我们的示例中,ProtocolLoggingLevel 显示身份SMTP 中继详细。这意味着日志记录已启用。

[PS] C:\>Get-ReceiveConnector -Server "EX01-2016" | ft Identity,Enabled,TransportRole,Protocol*,Bindings

Identity                                    Enabled     TransportRole ProtocolLoggingLevel Bindings
--------                                    -------     ------------- -------------------- --------
EX01-2016\Default EX01-2016                    True      HubTransport              Verbose {0.0.0.0:2525, [::]:2525}
EX01-2016\Client Proxy EX01-2016               True      HubTransport              Verbose {[::]:465, 0.0.0.0:465}
EX01-2016\Default Frontend EX01-2016           True FrontendTransport              Verbose {[::]:25, 0.0.0.0:25}
EX01-2016\Outbound Proxy Frontend EX01-2016    True FrontendTransport              Verbose {[::]:717, 0.0.0.0:717}
EX01-2016\Client Frontend EX01-2016            True FrontendTransport              Verbose {[::]:587, 0.0.0.0:587}
EX01-2016\SMTP relay                           True FrontendTransport              Verbose {0.0.0.0:25}

您可以在 Exchange 管理中心检查 SMTP 日志记录状态。转到邮件流>接收连接器。选择您要检查的 Exchange 服务器。选择 SMTP 中继接收连接器并检查详细信息窗格是否显示日志记录 - 打开

注意:如果您的组织中有多个 Exchange Server,您很可能在多个 Exchange Server 上配置了 SMTP 中继接收连接器以实现高可用性。检查所有 Exchange 服务器上是否启用 SMTP 中继接收连接器日志记录。

[玩转系统] 使用 Exchange SMTP 中继查找 IP 地址

如果启用了 SMTP 日志记录,请跳过下一步。如果没有,请在下一步中启用 SMTP 中继接收连接器的日志记录。它很可能是传输角色FrontendTransport

启用 SMTP 中继日志

[PS] C:\>Get-ReceiveConnector -Identity "EX01-2016\SMTP relay" | Set-ReceiveConnector -ProtocolLogging Verbose

您想在 Exchange 管理中心启用 SMTP 中继日志记录吗?单击详细信息窗格中的打开链接以启用 SMTP 日志记录。在其他 Exchange 服务器上执行相同的操作。

[玩转系统] 使用 Exchange SMTP 中继查找 IP 地址

如果您现在启用了 SMTP 中继接收连接器日志记录,则必须等待几天或几周才能生成日志。这取决于用途。

查找 SMTP 中继日志

在 Exchange 管理中心中找不到 Exchange SMTP 日志路径。我们需要使用 Exchange Management Shell 并找到 SMTP 日志的放置位置。

[PS] C:\>Get-FrontendTransportService -Identity "EX01-2016" | fl Name,Identity,Receive*


Name                               : EX01-2016
Identity                           : Frontend
ReceiveProtocolLogMaxAge           : 30.00:00:00
ReceiveProtocolLogMaxDirectorySize : 250 MB (262,144,000 bytes)
ReceiveProtocolLogMaxFileSize      : 10 MB (10,485,760 bytes)
ReceiveProtocolLogPath             : C:\Program Files\Microsoft\Exchange Server\V15\TransportRoles\Logs\FrontEnd\ProtocolLog\SmtpReceive

复制 ReceiveProtocolLogPath 并将其粘贴到 Windows 资源管理器中。

[玩转系统] 使用 Exchange SMTP 中继查找 IP 地址

在下一步中,我们将准备 PowerShell 脚本来扫描所有日志并过滤掉 IP 地址。

了解更多:Exchange 接收连接器日志记录 »

准备 SMTP-Review PowerShell 脚本

在 Exchange Server (C:) 驱动器上创建两个文件夹:

  • 温度

  • 脚本

下载 SMTP-Review.ps1 PowerShell 脚本并将其放置在 C:\scripts 文件夹中。该脚本会将文本文件导出到 C:\temp 文件夹。

确保文件未被阻止,以防止运行脚本时出现错误。请阅读文章运行 PowerShell 脚本时出现未数字签名错误来了解更多信息。

另一种选择是将以下代码复制并粘贴到记事本中。将其命名为 SMTP-Review.ps1 并将其放置在 C:\scripts 文件夹中。

<#
    .SYNOPSIS
    SMTP-Review.ps1

    .DESCRIPTION
    Script is intended to help determine servers that are using an Exchange server to connect and send email.
    This is especially pertinent in a decommission scenario, where the logs are to be checked to ensure that
    all SMTP traffic has been moved to the correct endpoint.

    .LINK
    www.a-d.site/find-ip-addresses-using-exchange-smtp-relay

    .NOTES
    Written by: ALI TAJRAN
    Website:    www.a-d.site
    LinkedIn:   linkedin.com/in/a-d

    .CHANGELOG
    V1.00, 04/05/2021 - Initial version
    V2.00, 03/28/2023 - Rewrite script to retrieve results faster
#>

# Clears the host console to make it easier to read output
Clear-Host

# Sets the path to the directory containing the log files to be processed
$logFilePath = "C:\Program Files\Microsoft\Exchange Server\V15\TransportRoles\Logs\FrontEnd\ProtocolLog\SmtpReceive\*.log"

# Sets the path to the output file that will contain the unique IP addresses
$Output = "C:\temp\IPAddresses.txt"

# Gets a list of the log files in the specified directory
$logFiles = Get-ChildItem $logFilePath

# Gets the number of log files to be processed
$count = $logFiles.Count

# Initializes an array to store the unique IP addresses
$ips = foreach ($log in $logFiles) {

    # Displays progress information
    $percentComplete = [int](($logFiles.IndexOf($log) + 1) / $count * 100)
    $status = "Processing $($log.FullName) - $percentComplete% complete ($($logFiles.IndexOf($log)+1) of $count)"
    Write-Progress -Activity "Collecting Log details" -Status $status -PercentComplete $percentComplete

    # Displays the name of the log file being processed
    Write-Host "Processing Log File $($log.FullName)" -ForegroundColor Magenta

    # Reads the content of the log file, skipping the first five lines
    $fileContent = Get-Content $log | Select-Object -Skip 5

    # Loops through each line in the log file
    foreach ($line in $fileContent) {

        # Extracts the IP address from the socket information in the log line
        $socket = $line.Split(',')[5]
        $ip = $socket.Split(':')[0]
        
        # Adds the IP address to the $ips array
        $ip
    }
}

# Removes duplicate IP addresses from the $ips array and sorts them alphabetically
$uniqueIps = $ips | Select-Object -Unique | Sort-Object

# Displays the list of unique IP addresses on the console
Write-Host "List of noted remove IPs:" 
$uniqueIps
Write-Host 

# Writes the list of unique IP addresses to the output file
$uniqueIps | Out-File $Output

这就是它在文件资源管理器中的外观。

[玩转系统] 使用 Exchange SMTP 中继查找 IP 地址

第 27 行中,将路径更改为您在上一步中搜索的接收协议日志路径。

在我们的示例中,它是这样的:

$LogFilePath = "C:\Program Files\Microsoft\Exchange Server\V15\TransportRoles\Logs\FrontEnd\ProtocolLog\SmtpReceive\*.log"

运行 SMTP-Review PowerShell 脚本

以管理员身份运行 PowerShell 并运行 SMTP-Review.ps1 PowerShell 脚本。

注意:如果您配置了 SMTP 中继,请在所有 Exchange 服务器上运行该脚本。例如,Exchange Server EX01-2016 和 EX02-2016。

PS C:\> cd C:\scripts
PS C:\scripts> .\SMTP-Review.ps1

该脚本将遍历所有文件,完成后,您将在控制台输出中看到哪些 IP 地址使用 SMTP 中继。此外,它还会在 C:\temp 文件夹中生成一个包含 IP 地址的 IPAddresses.txt 文件。

[玩转系统] 使用 Exchange SMTP 中继查找 IP 地址

记下 IP 地址并将打印机、应用程序和服务器中的 SMTP 字段调整为新的 SMTP 中继记录。

您可能感兴趣的其他文章:

  • 将远程 IP 地址导出到 Exchange 接收连接器

  • 将远程 IP 地址导入到 Exchange 接收连接器

  • 将接收连接器复制到另一个 Exchange Server

结论

您学习了如何使用 Exchange SMTP 中继查找 IP 地址。在 SMTP 中继接收连接器上启用日志记录并在开始之前复制日志路径。运行 SMTP-Review.ps1 PowerShell 脚本并让它运行 SMTP 接收日志。不要忘记在配置了 SMTP 中继接收连接器的所有 Exchange 服务器上运行该脚本。

脚本完成后,调整上述 IP 地址上的 SMTP 记录。使用该脚本的另一个好方法是了解哪些 IP 地址已过时,并将其从接收连接器 IP 地址列表中删除。

您喜欢这篇文章吗?您可能还喜欢 Microsoft Exchange Server 漏洞检查。不要忘记关注我们并分享这篇文章。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯