PlusMagi's Blog By Pitt Phunsanit Backend,Cloud Computing วิธีใช้ Command Ping เพื่อตรวจสอบเครื่องที่เปิดอยู่ในเครือข่ายภายในบ้าน/งาน

วิธีใช้ Command Ping เพื่อตรวจสอบเครื่องที่เปิดอยู่ในเครือข่ายภายในบ้าน/งาน

แทนที่จะไล่หาว่าเครื่องไหนมันเปิดอยู่บ้างที่ละเครื่องสามารถใช้ command ping เครือข่ายทั้งยวงได้โดยใช้คำสั่ง

Code

FOR /L %i IN (1,1,254) DO ping -n 1 192.168.1.%i | FIND /i "Reply">>c:ipaddresses.txt

ผลที่ได้จะถูกเขียนลงในไฟล์ c:\ipaddresses.txt

Code

...
Reply from 192.168.1.1: Destination host unreachable.
Reply from 192.168.1.1: Destination host unreachable.
Reply from 192.168.1.1: Destination host unreachable.
...
Reply from 192.168.1.61: bytes=32 time=2ms TTL=64
Reply from 192.168.1.62: bytes=32 time=5ms TTL=64
Reply from 192.168.1.63: bytes=32 time<1ms TTL=128
Reply from 192.168.1.64: bytes=32 time<1ms TTL=128
...
Reply from 192.168.1.1: Destination host unreachable.
...

อธิบายคือไล่ ping เครื่องตั้งแต่ ip 192.168.1.1 ถึง 192.168.1.254 ถ้าเครื่องไหนตอบกลับมา (เปิดอยู่) แล้วเขียนไว้ในไฟล์ c:ipaddresses.txt ถ้าเปิดดูก็จะเห็นตัวหนังสือประมาณ bytes=32 time=2ms TTL=64 ส่วนที่หาไม่เจอ ไม่ตอบกลับมา ก็จะได้ข้อความซ้ำ ๆ มาจาก router อย่าง Reply from 192.168.1.1: Destination host unreachable.

ดีกว่าไล่ดูทีละเครื่องเยอะเลย
Cr: Ping all addresses in network, windows

Tags: , ,