PHP Ping Command Line: Execute the ping command to check a remote machine

Recommend this page to a friend!
  Info   View files Documentation   View files View files (40)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-09-21 (Yesterday) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
acamposm_ping 1.0Custom (specified...7.4Networking, PHP 5, Unix, Windows
Description Author

This package can execute the ping command to check a remote machine.

It can execute the ping command on different systems and parsers the output to return details of the remote machine response.

The package provides wrappers that support the ping command either on Linux or on Windows.

Picture of Angel Campos
Name: Angel Campos <contact>
Classes: 1 package by
Country: Spain Spain

Details

PING for Laravel

License Latest Stable Version Latest Unstable Version Build Status Scrutinizer Code Quality StyleCI Total Downloads

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

You can install the package via composer and then publish the assets:


composer require acamposm/ping

php artisan vendor:publish --provider="Acamposm\Ping\PingServiceProvider"

*Note:* We try to follow SemVer v2.0.0.

Usage

For basic usage you only need to create with an ip address as a first argument and run...


use Acampos\Ping\Ping;
use Acampos\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.


// 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.


// 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.


// 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.


// 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.


// 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


$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);

=> {#613
    +"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": {#616
        +"avg": 0.036,
        +"min": 0.036,
        +"max": 0.037,
    },
    +"sequence": {#615
        +"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": {#614
        +"packets_transmitted": 10,
        +"packets_received": 10,
        +"packets_lost": 0,
        +"packet_loss": 0,
    },
    +"options": {#598
        +"host": "google.com",
        +"count": 10,
        +"packet_size": 200,
        +"ttl": 120,
    },
    +"time": {#610
        +"start": {#612
            +"as_float": 1596984650.5006,
            +"human_readable": "09-08-2020 14:50:50.500600",
        },
        +"stop": {#611
            +"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


$command = (new PingCommandBuilder('192.168.10.254'))->count(10)->packetSize(200)->ttl(120);

$ping = (new Ping($command))->run();

dd($ping);

=> {#615
    +"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": {#618
        +"avg": 0.0,
        +"min": 0.0,
        +"max": 0.0,
    },
    +"sequence": {#598
        +"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": {#616
        +"packets_transmitted": 10,
        +"packets_received": 10,
        +"packets_lost": 0,
        +"packet_loss": 0,
    },
    +"options": {#619
        +"host": "192.168.10.254",
        +"count": 10,
        +"packet_size": 200,
        +"ttl": 120,
        +"version": 4,
    },
    +"time": {#612
    +"start": {#614
        +"as_float": 1596985359.7592,
        +"human_readable": "09-08-2020 15:02:39.759200",
    },
    +"stop": {#613
        +"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

    
$command = (new PingCommandBuilder('fe80::6c42:407d:af01:9567'))->count(10)->packetSize(200)->ttl(120);

$ping = (new Ping($command))->run();

dd($ping);

=> {#615
    +"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",
        "",
        b"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:",
        b"    Mínimo = 0ms, Máximo = 0ms, Media = 0ms",
    ],
    +"latency": 0.0,
    +"rtt": {#618
        +"avg": 0.0,
        +"min": 0.0,
        +"max": 0.0,
    },
    +"sequence": {#598
        +"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": {#616
        +"packets_transmitted": 10,
        +"packets_received": 10,
        +"packets_lost": 0,
        +"packet_loss": 0,
    },
    +"options": {#619
        +"host": "fe80::6c42:407d:af01:9567",
        +"count": 10,
        +"packet_size": 200,
        +"ttl": 120,
        +"version": 6,
    },
    +"time": {#612
        +"start": {#614
            +"as_float": 1596985675.4344,
            +"human_readable": "09-08-2020 15:07:55.434400",
        },
        +"stop": {#613
            +"as_float": 1596985684.4659,
            +"human_readable": "09-08-2020 15:08:04.465900",
        },
        +"time": 9.032,
    },
}

Testing


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.

Credits

License

The package Ping is open-source package and is licensed under The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

  Files folder image Files  
File Role Description
Files folder image.github (3 files, 1 directory)
Files folder image.idea (6 files)
Files folder imageconfig (1 file)
Files folder imagesrc (7 files, 3 directories)
Files folder imagetests (3 files)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .env.travis Data Auxiliary data
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  .github  
File Role Description
Files folder imageISSUE_TEMPLATE (1 file)
  Accessible without login Plain text file CODE_OF_CONDUCT.md Data Auxiliary data
  Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
  Accessible without login Plain text file SECURITY.md Data Auxiliary data

  Files folder image Files  /  .github  /  ISSUE_TEMPLATE  
File Role Description
  Accessible without login Plain text file bug_report.md Data Auxiliary data

  Files folder image Files  /  .idea  
File Role Description
  Accessible without login Plain text file misc.xml Data Auxiliary data
  Accessible without login Plain text file modules.xml Data Auxiliary data
  Accessible without login Plain text file php.xml Data Auxiliary data
  Accessible without login Plain text file phpunit.xml Data Auxiliary data
  Accessible without login Plain text file ping.iml Data Auxiliary data
  Accessible without login Plain text file vcs.xml Data Auxiliary data

  Files folder image Files  /  config  
File Role Description
  Accessible without login Plain text file config.php Aux. Auxiliary script

  Files folder image Files  /  src  
File Role Description
Files folder imageExceptions (5 files)
Files folder imageInterfaces (2 files)
Files folder imageParsers (3 files)
  Plain text file IPAddress.php Class Class source
  Plain text file Ping.php Class Class source
  Plain text file PingCommandBuilder.php Class Class source
  Plain text file PingFacade.php Class Class source
  Plain text file PingServiceProvider.php Class Class source
  Plain text file System.php Class Class source
  Plain text file Timer.php Class Class source

  Files folder image Files  /  src  /  Exceptions  
File Role Description
  Plain text file InvalidIPAddressException.php Class Class source
  Plain text file MaxValueException.php Class Class source
  Plain text file NegativeValueException.php Class Class source
  Plain text file TimerNotStartedException.php Class Class source
  Plain text file UnknownOSException.php Class Class source

  Files folder image Files  /  src  /  Interfaces  
File Role Description
  Plain text file PingCommand.php Class Class source
  Plain text file PingParserInterface.php Class Class source

  Files folder image Files  /  src  /  Parsers  
File Role Description
  Plain text file PingParser.php Class Class source
  Plain text file PingParserForLinux.php Class Class source
  Plain text file PingParserForWindows.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file IPAddressTest.php Class Class source
  Plain text file PingCommandBuilderTest.php Class Class source
  Plain text file TestCase.php Class Class source

 Version Control Unique User Downloads  
 100%
Total:0
This week:0

For more information send a message to info at phpclasses dot org.