# 第五十课：基于SqlDataSourceEnumerator发现内网存活主机

从 xp 开始默认有 .net framework,在 powershell 后，调用起来更方便。

## 连载1

System.Data.SqlClient 命名空间是用于 SQL Server 的 .NET 数据提供程序。在net framework2.0中新增加SqlDataSourceEnumerator 类。提供了一种枚举本地网络内的所有可用 SQL Server 实例机制。微软官方是这样解释的：

> SQL Server 2000 和 SQL Server 2005 进行应用程序可以确定在当前网络中的 SQL Server实例存在。SqlDataSourceEnumerator类公开给应用程序开发人员，提供此信息DataTable包含所有可用的服务器的信息。返回此表列出了与列表匹配提供当用户尝试创建新的连接的服务器实例以及Connection Properties对话框中，展开下拉列表，其中包含所有可用的服务器。

```bash
PowerShell -Command 
"[System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources()"
```

![](/files/-LZJwrlQ_T0wEfd94Pvm)

![](/files/-LZJwrlSCio5k5bE2zhZ)

此种方法，在实战中，不留文件痕迹。并且信息准确，发现主机也可。可应对目前主流安全防御产品。

> Micropoor


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://micro8.gitbook.io/micro8/contents-1/41-50/50-ji-yu-sqldatasourceenumerator-fa-xian-nei-wang-cun-huo-zhu-ji.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
