0
從URL格式,如何使用PowerShell獲取協議,機器名稱和端口號。如何使用正則表達式從URL格式獲取機器名稱,協議和端口號?
This page fetch protocol and port number using C#。但我也想知道機器名稱,需要使用PowerShell。
從URL格式,如何使用PowerShell獲取協議,機器名稱和端口號。如何使用正則表達式從URL格式獲取機器名稱,協議和端口號?
This page fetch protocol and port number using C#。但我也想知道機器名稱,需要使用PowerShell。
你可以使用:
$a = [System.Uri]"http://www.contoso.com:8080/letters/readme.html"
然後:
$a | fl *
AbsolutePath : /letters/readme.html
AbsoluteUri : http://www.contoso.com:8080/letters/readme.html
LocalPath : /letters/readme.html
Authority : www.contoso.com:8080
HostNameType : Dns
IsDefaultPort : False
IsFile : False
IsLoopback : False
PathAndQuery : /letters/readme.html
Segments : {/, letters/, readme.html}
IsUnc : False
Host : www.contoso.com
Port : 8080
Query :
Fragment :
Scheme : http
OriginalString : http://www.contoso.com:8080/letters/readme.html
DnsSafeHost : www.contoso.com
IsAbsoluteUri : True
UserEscaped : Fa
所以對於協議Http
由下式給出:
$a.Scheme
這是神奇的。 – Matt
你可以只建立一個['Uri'] (https://msdn.microsoft.com/en-us/library/system.uri%28v=vs.110%29.aspx)並訪問相應的屬性(注意,當然,您可以獲得作爲域名或IP地址的「權限」。無法通過URI知道機器的* actual *名稱) –