読者です 読者をやめる 読者になる 読者になる

或阿呆のブログ

Pythonを好んで使っているプログラマです。Ruby,Perl,PowerShell,VBAなどでもたまに書いています。おバカなことが大好きです。

WindowsPowerShellでPing疎通確認。接続確認出来たら。。。

今時ping...

PS>ping localhost

Tom-PC [::1]に ping を送信しています 32 バイトのデータ:
::1 からの応答: 時間 <1ms 
::1 からの応答: 時間 <1ms 
::1 からの応答: 時間 <1ms 
::1 からの応答: 時間 <1ms 

::1 の ping 統計:
    パケット数: 送信 = 4、受信 = 4、損失 = 0 (0% の損失)、
ラウンド トリップの概算時間 (ミリ秒):
    最小 = 0ms、最大 = 0ms、平均 = 0ms

これからはTest-Connection

PS>Test-Connection localhost

Source        Destination     IPV4Address      IPV6Address                     
------        -----------     -----------      -----------                     
TOM-PC        localhost       127.0.0.1        ::1                             
TOM-PC        localhost       127.0.0.1        ::1                             
TOM-PC        localhost       127.0.0.1        ::1                             
TOM-PC        localhost       127.0.0.1        ::1                             

変わらんやんとか言ったら甘いで。

Test-Connectionで1行だけ

PS>Test-Connection localhost | select-object -First 1

Source        Destination     IPV4Address      IPV6Address                     
------        -----------     -----------      -----------                     
TOM-PC        localhost       127.0.0.1        ::1 

Test-ConnectionでListで全プロパティ

PS>Test-Connection localhost | Format-List


__GENUS                        : 2
__CLASS                        : Win32_PingStatus
__SUPERCLASS                   : 
__DYNASTY                      : Win32_PingStatus
__RELPATH                      : Win32_PingStatus.Address="localhost",BufferSiz
                                 e=32,NoFragmentation=FALSE,RecordRoute=0,Resol
                                 veAddressNames=FALSE,SourceRoute="",SourceRout
                                 eType=0,Timeout=4000,TimestampRoute=0,TimeToLi
                                 ve=80,TypeofService=0
__PROPERTY_COUNT               : 24
__DERIVATION                   : {}
__SERVER                       : TOM-PC
__NAMESPACE                    : root\cimv2
__PATH                         : \\TOM-PC\root\cimv2:Win32_PingStatus.Address="
                                 localhost",BufferSize=32,NoFragmentation=FALSE
                                 ,RecordRoute=0,ResolveAddressNames=FALSE,Sourc
                                 eRoute="",SourceRouteType=0,Timeout=4000,Times
                                 tampRoute=0,TimeToLive=80,TypeofService=0
Address                        : localhost
BufferSize                     : 32
NoFragmentation                : False
PrimaryAddressResolutionStatus : 0
ProtocolAddress                : ::1
ProtocolAddressResolved        : 
RecordRoute                    : 0
ReplyInconsistency             : 
ReplySize                      : 
ResolveAddressNames            : False
ResponseTime                   : 0
ResponseTimeToLive             : 
RouteRecord                    : 
RouteRecordResolved            : 
SourceRoute                    : 
SourceRouteType                : 0
StatusCode                     : 0
Timeout                        : 4000
TimeStampRecord                : 
TimeStampRecordAddress         : 
TimeStampRecordAddressResolved : 
TimestampRoute                 : 0
TimeToLive                     : 80
TypeofService                  : 0
PSComputerName                 : TOM-PC
IPV4Address                    : 127.0.0.1
IPV6Address                    : ::1

__GENUS                        : 2
__CLASS                        : Win32_PingStatus
__SUPERCLASS                   : 
__DYNASTY                      : Win32_PingStatus
__RELPATH                      : Win32_PingStatus.Address="localhost",BufferSiz
                                 e=32,NoFragmentation=FALSE,RecordRoute=0,Resol
                                 veAddressNames=FALSE,SourceRoute="",SourceRout
                                 eType=0,Timeout=4000,TimestampRoute=0,TimeToLi
                                 ve=80,TypeofService=0
__PROPERTY_COUNT               : 24
__DERIVATION                   : {}
__SERVER                       : TOM-PC
__NAMESPACE                    : root\cimv2
__PATH                         : \\TOM-PC\root\cimv2:Win32_PingStatus.Address="
                                 localhost",BufferSize=32,NoFragmentation=FALSE
                                 ,RecordRoute=0,ResolveAddressNames=FALSE,Sourc
                                 eRoute="",SourceRouteType=0,Timeout=4000,Times
                                 tampRoute=0,TimeToLive=80,TypeofService=0
Address                        : localhost
BufferSize                     : 32
NoFragmentation                : False
PrimaryAddressResolutionStatus : 0
ProtocolAddress                : ::1
ProtocolAddressResolved        : 
RecordRoute                    : 0
ReplyInconsistency             : 
ReplySize                      : 
ResolveAddressNames            : False
ResponseTime                   : 0
ResponseTimeToLive             : 
RouteRecord                    : 
RouteRecordResolved            : 
SourceRoute                    : 
SourceRouteType                : 0
StatusCode                     : 0
Timeout                        : 4000
TimeStampRecord                : 
TimeStampRecordAddress         : 
TimeStampRecordAddressResolved : 
TimestampRoute                 : 0
TimeToLive                     : 80
TypeofService                  : 0
PSComputerName                 : TOM-PC
IPV4Address                    : 127.0.0.1
IPV6Address                    : ::1

__GENUS                        : 2
__CLASS                        : Win32_PingStatus
__SUPERCLASS                   : 
__DYNASTY                      : Win32_PingStatus
__RELPATH                      : Win32_PingStatus.Address="localhost",BufferSiz
                                 e=32,NoFragmentation=FALSE,RecordRoute=0,Resol
                                 veAddressNames=FALSE,SourceRoute="",SourceRout
                                 eType=0,Timeout=4000,TimestampRoute=0,TimeToLi
                                 ve=80,TypeofService=0
__PROPERTY_COUNT               : 24
__DERIVATION                   : {}
__SERVER                       : TOM-PC
__NAMESPACE                    : root\cimv2
__PATH                         : \\TOM-PC\root\cimv2:Win32_PingStatus.Address="
                                 localhost",BufferSize=32,NoFragmentation=FALSE
                                 ,RecordRoute=0,ResolveAddressNames=FALSE,Sourc
                                 eRoute="",SourceRouteType=0,Timeout=4000,Times
                                 tampRoute=0,TimeToLive=80,TypeofService=0
Address                        : localhost
BufferSize                     : 32
NoFragmentation                : False
PrimaryAddressResolutionStatus : 0
ProtocolAddress                : ::1
ProtocolAddressResolved        : 
RecordRoute                    : 0
ReplyInconsistency             : 
ReplySize                      : 
ResolveAddressNames            : False
ResponseTime                   : 0
ResponseTimeToLive             : 
RouteRecord                    : 
RouteRecordResolved            : 
SourceRoute                    : 
SourceRouteType                : 0
StatusCode                     : 0
Timeout                        : 4000
TimeStampRecord                : 
TimeStampRecordAddress         : 
TimeStampRecordAddressResolved : 
TimestampRoute                 : 0
TimeToLive                     : 80
TypeofService                  : 0
PSComputerName                 : TOM-PC
IPV4Address                    : 127.0.0.1
IPV6Address                    : ::1

__GENUS                        : 2
__CLASS                        : Win32_PingStatus
__SUPERCLASS                   : 
__DYNASTY                      : Win32_PingStatus
__RELPATH                      : Win32_PingStatus.Address="localhost",BufferSiz
                                 e=32,NoFragmentation=FALSE,RecordRoute=0,Resol
                                 veAddressNames=FALSE,SourceRoute="",SourceRout
                                 eType=0,Timeout=4000,TimestampRoute=0,TimeToLi
                                 ve=80,TypeofService=0
__PROPERTY_COUNT               : 24
__DERIVATION                   : {}
__SERVER                       : TOM-PC
__NAMESPACE                    : root\cimv2
__PATH                         : \\TOM-PC\root\cimv2:Win32_PingStatus.Address="
                                 localhost",BufferSize=32,NoFragmentation=FALSE
                                 ,RecordRoute=0,ResolveAddressNames=FALSE,Sourc
                                 eRoute="",SourceRouteType=0,Timeout=4000,Times
                                 tampRoute=0,TimeToLive=80,TypeofService=0
Address                        : localhost
BufferSize                     : 32
NoFragmentation                : False
PrimaryAddressResolutionStatus : 0
ProtocolAddress                : ::1
ProtocolAddressResolved        : 
RecordRoute                    : 0
ReplyInconsistency             : 
ReplySize                      : 
ResolveAddressNames            : False
ResponseTime                   : 0
ResponseTimeToLive             : 
RouteRecord                    : 
RouteRecordResolved            : 
SourceRoute                    : 
SourceRouteType                : 0
StatusCode                     : 0
Timeout                        : 4000
TimeStampRecord                : 
TimeStampRecordAddress         : 
TimeStampRecordAddressResolved : 
TimestampRoute                 : 0
TimeToLive                     : 80
TypeofService                  : 0
PSComputerName                 : TOM-PC
IPV4Address                    : 127.0.0.1
IPV6Address                    : ::1

Test-Connetionで疎通出来るかだけ確認

PS>Test-Connection localhost -Quiet
True

メリットわからん?

Test-Connetionで疎通出来たらHello,PowerShell

PS>if(Test-Connection localhost -Quiet){echo "Hello,PowerShell!"}
Hello,PowerShell!

これ、便利よね。IPアドレス一覧を読み込んで、疎通出来たものだけ絞るとかも出来る!!!

みるくたん大好き

PS>if(Test-Connection localhost -Quiet){echo "Hello!みるくたん!"}
Hello!みるくたん!