gpt4 book ai didi

asp.net - 如何查找 URL 注册(不是预订)?

转载 作者:行者123 更新时间:2023-12-03 11:06:22 25 4
gpt4 key购买 nike

是否有 Windows 命令列出持有特定 URL 注册的应用程序的进程 ID 和名称?

我关注在以下 URL 命名空间下进行注册的应用程序。

http://localhost:55987/

我知道可以使用 URL Reservations 列出
netsh http show urlacl
保留指出,
 Reserved URL            : http://localhost:55987/
User: \Everyone
Listen: Yes
Delegate: No
SDDL: D:(A;;GX;;;WD)

但是如何找到在保留的 URL 命名空间下进行的注册?

最佳答案

您可以使用以下命令找到已注册 url 的 processId:

netsh http show servicestate view=requestq verbose=no

它将返回一个如下所示的表:
    Request queue name: Request queue is unnamed.
Version: 2.0
State: Active
Request queue 503 verbosity level: Basic
Max requests: 1000
Number of active processes attached: 1
Process IDs:
3604
URL groups:
URL group ID: F100000040000003
State: Active
Request queue name: Request queue is unnamed.
Number of registered URLs: 1
Registered URLs:
HTTP://+:8022/
Server session ID: F200000020000007
Version: 2.0
State: Active
Request queue name: Request queue is unnamed.
Version: 2.0
State: Active
Request queue 503 verbosity level: Basic
Max requests: 1000
Number of active processes attached: 1
Process IDs:
3604
URL groups:
URL group ID: D400000040001E9C
State: Active
Request queue name: Request queue is unnamed.
Number of registered URLs: 1
Registered URLs:
HTTP://+:3799/API
Server session ID: D6000000200013C1
Version: 2.0
State: Active

我还制作了一个 powershell 函数,它解析这个输出以返回一个对象列表。

结果样本:
ProcessId                               ControllerProcessId                     RegisteredUrl
--------- ------------------- -------------
1860 HTTP://+:8022/
1020 HTTPS://+:5986/WSMAN/

function Parse-HttpSysReqQueue() {
[string[]]$rawHttpSysQueue = netsh http show servicestate view=requestq verbose=no

$urls = @()
$output = @()
$recordIsOpen = $false
$index = 0
$rawHttpSysQueue | ForEach-Object {
$line = $_

# Whether is the begining of a new request queue record.
$newRecordToken = "Request queue name"
if ($line.StartsWith($newRecordToken)) {
$recordIsOpen = $true
$index++; return
}

# We are iterating through a request-queue record.
if ($recordIsOpen) {

# Obtain Process ID
if ($line.Contains("Process IDs:")) {
$rawPid = $rawHttpSysQueue[$index+1]
if($rawPid.Trim() -match '^\d+$'){
$processId = $rawPid.Trim()
} else {
$processId = $null
}
$index++; return
}

# Obtain Controller Process ID (generally IIS)
if ($line.Contains("Controller process ID:")) {
$controllerProcessId = $line.Split(":")[1].Trim()
$index++; return
}

# Read all registered urls from current record.
if ($line.Contains("Registered URLs:")) {
$urlLineIndex = $index+1
while ($rawHttpSysQueue[$urlLineIndex].Trim().StartsWith("HTTP://") -or $rawHttpSysQueue[$urlLineIndex].Trim().StartsWith("HTTPS://")) {
$urls += $rawHttpSysQueue[$urlLineIndex].Trim()
$urlLineIndex++
}

# Add record to output list.
$urls | ForEach-Object {
$output += New-Object PSObject -Property @{
ProcessId = $processId
RegisteredUrl = $_
ControllerProcessId = $controllerProcessId
}
}

# Already read all the urls from this request-queue, consider the record closed.
$processId = $null
$controllerProcessId = $null
$urls = @()
$recordIsOpen = $false
}
}
$index++
}

return $output
}

关于asp.net - 如何查找 URL 注册(不是预订)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54943838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com