官术网_书友最值得收藏!

Pinging from another computer over same network

Now that we have our computer on the network, we want to make sure other computers are able to contact it. The ping command is one of the first tests to tell whether your computer can be contacted. The command sends a small test packet of data to another computer's IP address or hostname and waits to hear a response. If it does, it tells you how long it took for the response to come back. If it doesn't, it tells you it is not receiving a response.

Note

Some computer systems have firewalls that do not allow ICMP ECHO attempts. This means that even though the computer is available on the network, attempts to ping it will fail. On the default configuration of Raspbian, ping commands are allowed, so attempts to ping your Pi should succeed.

Getting ready

As long you as you know your IP address (whether it was dynamically assigned using DHCP or you assigned a static IP from the previous recipe), you should be able to contact it from your network. The easiest way to do this is by looking at ifconfig. From your serial terminal connection, and if you followed one of the previous recipes to add Wi-Fi connectivity, ifconfig should report the IP address of your Raspberry Pi Zero:

pi@rpz14101:~$ ifconfig
lo Link encap:Local Loopback
 inet addr:127.0.0.1 Mask:255.0.0.0
 inet6 addr: ::1/128 Scope:Host
 UP LOOPBACK RUNNING MTU:65536 Metric:1
 RX packets:264 errors:0 dropped:0 overruns:0 frame:0
 TX packets:264 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:1
 RX bytes:21840 (21.3 KiB) TX bytes:21840 (21.3 KiB)
wlan0 Link encap:Ethernet HWaddr 00:13:ef:80:0b:41
inet addr:192.168.2.119 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::a577:b1b7:a7a7:8a60/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:212682 errors:0 dropped:54847 overruns:0 frame:0
TX packets:19599 errors:0 dropped:1 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:34267586 (32.6 MiB) TX bytes:1911492 (1.8 MiB)

The wlan0 interface is the one I set up in the previous recipe. The inet addr field shows my Raspberry Pi Zero's IP address. This is the one I want to try and contact.

How to do it...

  1. ping <IP address>, like this, for example:

    ping 192.168.2.119

  2. On a Windows machine, you can execute ping via the command line (Windows + R followed by cmd). Below is a shot of a typical successful response:
  3. Trying 192.168.2.120, which isn't assigned to anything on my home network, will show a failed ping:

This means that there is nothing responding from that IP address, which could mean it is down, off, or blocked by a firewall. The command ping /? will give you all available options for the Windows ping command. By default, the Windows ping tries four times and reports the results.

In an OSX or Linux terminal, the ping utility will continue trying to reach the address and report back the response time (or whether it failed). Breaking the utility with Ctrl  + C will stop it.

Running ping -help will give you a list of all the options, and man ping will give you a more detailed document of what is possible. A few favorite flags of administrators are the following:

ping -c 5 192.168.2.70

This will try to ping 5 times and then stop.

ping -i 2 192.168.2.70

This will send a ping command every 2 seconds.

主站蜘蛛池模板: 越西县| 阿图什市| 凤翔县| 涿州市| 佛教| 瑞金市| 略阳县| 庄河市| 赫章县| 分宜县| 辉县市| 西盟| 永春县| 晋宁县| 葫芦岛市| 郓城县| 特克斯县| 卓资县| 青州市| 武穴市| 叙永县| 那坡县| 南充市| 延长县| 贵州省| 德格县| 弥勒县| 西畴县| 达孜县| 吉木萨尔县| 梁山县| 赤城县| 育儿| 长子县| 黄陵县| 泗水县| 会宁县| 香港 | 北碚区| 库尔勒市| 中方县|