ryangurn/ping
Composer 安装命令:
composer require ryangurn/ping
包简介
Ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway.
README 文档
README
This ping class allow making ping request from Laravel applications, it is based on PING command from the linux iputils package.
ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway. ECHO_REQUEST datagrams (pings) have an IP and ICMP header, followed by a struct timeval and then an arbitrary number ofpadbytes used to fill out the packet.
- Installation
- Usage
- Sample output
- Testing
- Changelog
- Contributing
- Security & Vulnerabilities
- Standards
- Credits
- License
Installation
You can install the package via composer and then publish the assets:
Prior to Ping 2.1.0 version you can install with:
composer require acamposm/ping
php artisan vendor:publish --provider="Acamposm\Ping\PingServiceProvider"
From Ping 2.1.0 version you can install with:
composer require acamposm/ping php artisan ping:install
Usage
For basic usage you only need to create with an ip address as a first argument and run...
use Acamposm\Ping\Ping; use Acamposm\Ping\PingCommandBuilder; // Create an instance of PingCommand $command = (new PingCommandBuilder('192.168.1.1')); // Pass the PingCommand instance to Ping and run... $ping = (new Ping($command))->run();
Change Count
Stop after sending count ECHO_REQUEST packets. With deadline option, ping waits for count ECHO_REPLY packets, until the timeout expires.
use Acamposm\Ping\Ping; use Acamposm\Ping\PingCommandBuilder; // Change the number of packets to send to 10 $command = (new PingCommandBuilder('192.168.1.1'))->count(10); $ping = (new Ping($command))->run();
Change Interval
Wait interval seconds between sending each packet. The default is to wait for one second between each packet normally, or not to wait in flood mode. Only super-user may set interval to values less than 0.2 seconds.
use Acamposm\Ping\Ping; use Acamposm\Ping\PingCommandBuilder; // Change interval to 0.5 seconds between each packet $command = (new PingCommandBuilder('192.168.1.1'))->interval(0.5); $ping = (new Ping($command))->run();
Change Packet Size
Specifies the number of data bytes to be sent. The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data.
use Acamposm\Ping\Ping; use Acamposm\Ping\PingCommandBuilder; // Change packet size to 128 $command = (new PingCommandBuilder('192.168.1.1'))->packetSize(128); $ping = (new Ping($command))->run();
Change Timeout
Time to wait for a response, in seconds. The option affects only timeout in absence of any responses, otherwise ping waits for two RTTs.
use Acamposm\Ping\Ping; use Acamposm\Ping\PingCommandBuilder; // Change timeout to 10 seconds $command = (new PingCommandBuilder('192.168.1.1'))->timeout(10); $ping = (new Ping($command))->run();
Change Time To Live
ping only. Set the IP Time to Live.
use Acamposm\Ping\Ping; use Acamposm\Ping\PingCommandBuilder; // Change Time To Live to 128 $command = (new PingCommandBuilder('192.168.1.1'))->ttl(128); $ping = (new Ping($command))->run();
Sample outputs
Here you can see three output samples of the ping command...
- The first with domain.
- The second with an IPv4 Address
- The third with an IPv6 Address
Sample output on Windows based server to https://google.com
use Acamposm\Ping\Ping; use Acamposm\Ping\PingCommandBuilder; $command = (new PingCommandBuilder('https://google.com'))->count(10)->packetSize(200)->ttl(128); // Sample output from Windows based server $ping = (new Ping($command))->run(); dd($ping);
{
"host_status": "Ok",
"raw": [
"",
"Haciendo ping a google.com [216.58.213.142] con 200 bytes de datos:",
"Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=37ms TTL=115",
"Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=37ms TTL=115",
"Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"",
"Estadísticas de ping para 216.58.213.142:",
" Paquetes: enviados = 10, recibidos = 10, perdidos = 0",
" (0% perdidos),",
"Tiempos aproximados de ida y vuelta en milisegundos:",
" Mínimo = 36ms, Máximo = 37ms, Media = 36ms",
],
"latency": 0.036,
"rtt": {
"avg": 0.036,
"min": 0.036,
"max": 0.037,
},
"sequence": {
"0": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"1": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"2": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"3": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=37ms TTL=115",
"4": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=37ms TTL=115",
"5": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"6": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"7": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"8": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
"9": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
},
"statistics": {
"packets_transmitted": 10,
"packets_received": 10,
"packets_lost": 0,
"packet_loss": 0,
},
"options": {
"host": "google.com",
"count": 10,
"packet_size": 200,
"ttl": 120,
},
"time": {
"start": {
"as_float": 1596984650.5006,
"human_readable": "09-08-2020 14:50:50.500600",
},
"stop": {
"as_float": 1596984659.5802,
"human_readable": "09-08-2020 14:50:59.580200",
},
"time": 9.08,
},
}
Sample output from Windows based server to local gateway IPv4
use Acamposm\Ping\Ping; use Acamposm\Ping\PingCommandBuilder; $command = (new PingCommandBuilder('192.168.10.254'))->count(10)->packetSize(200)->ttl(120); $ping = (new Ping($command))->run(); dd($ping);
{
"host_status": "Ok",
"raw": [
"",
"Haciendo ping a 192.168.10.254 con 200 bytes de datos:",
"Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"",
"Estadísticas de ping para 192.168.10.254:",
" Paquetes: enviados = 10, recibidos = 10, perdidos = 0",
" (0% perdidos),",
"Tiempos aproximados de ida y vuelta en milisegundos:",
" Mínimo = 0ms, Máximo = 0ms, Media = 0ms",
],
"latency": 0.0,
"rtt": {
"avg": 0.0,
"min": 0.0,
"max": 0.0,
},
"sequence": {
"0": "Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"1": "Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"2": "Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"3": "Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"4": "Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"5": "Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"6": "Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"7": "Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"8": "Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
"9": "Respuesta desde 192.168.10.254: bytes=200 tiempo<1m TTL=255",
},
"statistics": {
"packets_transmitted": 10,
"packets_received": 10,
"packets_lost": 0,
"packet_loss": 0,
},
"options": {
"host": "192.168.10.254",
"count": 10,
"packet_size": 200,
"ttl": 120,
"version": 4,
},
"time": {
"start": {
"as_float": 1596985359.7592,
"human_readable": "09-08-2020 15:02:39.759200",
},
"stop": {
"as_float": 1596985368.7952,
"human_readable": "09-08-2020 15:02:48.795200",
},
"time": 9.036,
},
}
Sample output from Windows based server to link local IPv6 address
use Acamposm\Ping\Ping; use Acamposm\Ping\PingCommandBuilder; $command = (new PingCommandBuilder('fe80::6c42:407d:af01:9567'))->count(10)->packetSize(200)->ttl(120); $ping = (new Ping($command))->run(); dd($ping);
{
"host_status": "Ok",
"raw": [
"",
"Haciendo ping a fe80::6c42:407d:af01:9567 con 200 bytes de datos:",
"Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"",
"Estadísticas de ping para fe80::6c42:407d:af01:9567:",
" Paquetes: enviados = 10, recibidos = 10, perdidos = 0",
" (0% perdidos),",
"Tiempos aproximados de ida y vuelta en milisegundos:",
" Mínimo = 0ms, Máximo = 0ms, Media = 0ms",
],
"latency": 0.0,
"rtt": {
"avg": 0.0,
"min": 0.0,
"max": 0.0,
},
"sequence": {
"0": "Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"1": "Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"2": "Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"3": "Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"4": "Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"5": "Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"6": "Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"7": "Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"8": "Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
"9": "Respuesta desde fe80::6c42:407d:af01:9567: tiempo<1m",
},
"statistics": {
"packets_transmitted": 10,
"packets_received": 10,
"packets_lost": 0,
"packet_loss": 0,
},
"options": {
"host": "fe80::6c42:407d:af01:9567",
"count": 10,
"packet_size": 200,
"ttl": 120,
"version": 6,
},
"time": {
"start": {
"as_float": 1596985675.4344,
"human_readable": "09-08-2020 15:07:55.434400",
},
"stop": {
"as_float": 1596985684.4659,
"human_readable": "09-08-2020 15:08:04.465900",
},
"time": 9.032,
},
}
Testing
For running the tests, in the console run:
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Thank you for considering contributing to the improvement of the package. Please see CONTRIBUTING for details.
Security & Vulnerabilities
If you discover any security related issues, please send an e-mail to Angel Campos via angel.campos.m@outlook.com instead of using the issue tracker. All security vulnerabilities will be promptly addressed.
Standards
The php package IPv4 Address Converter, comply with the next standards:
Credits
License
The package Ping is open-source package and is licensed under The MIT License (MIT). Please see License File for more information.
ryangurn/ping 适用场景与选型建议
ryangurn/ping 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「ping」 「icmp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ryangurn/ping 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ryangurn/ping 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ryangurn/ping 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway.
Ping for Laravel.
Native ping command without any dependencies. Through ICMP protocol.
Simple async lowlevel ICMP (ping) messages for react
Alfabank REST API integration
Está é uma biblioteca genérica voltada a efetuar testes/verificação de conectividade
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-22