How to make Ping tool with Ruby?
Ruby is the best programming language
Ping-rb
Hello people on the internet
I'm Meisam Heidari
Today I want to talk about my simple CLI tool to ping all systems in the world. It's a simple CLI tool, but it is a useful tool to ping computers and systems. You can send ICMP ECHO_REQUEST to network hosts with Ping-rb. Why do I call it Ping-rb?
besuse it's a simple ping tool, and it made with Ruby Programming language.
What does mean ping?
Ping is a computer network administration software utility used to test the reachability of a host on an Internet Protocol (IP) network. It is available for virtually all operating systems that have networking capability, including most embedded network administration software.
Ping measures the round-trip time for messages sent from the originating host to a destination computer that are echoed back to the source. The name comes from active sonar terminology that sends a pulse of sound and listens for the echo to detect objects under water.
Ping operates by means of Internet Control Message Protocol (ICMP) packets. Pinging involves sending an ICMP echo request to the target host and waiting for an ICMP echo reply. The program reports errors, packet loss, and a statistical summary of the results, typically including the minimum, maximum, the mean round-trip times, and standard deviation of the mean.
NOTE: This is the ping; Now you know everything about the ping. That is great, but if the ping software is installed in all computers and you can use it any way, why did I make that again?
The answer is, I just want to learn better, and I want to know how it's work? So I decide to make ping software by my self. Yeh!
How did I make Ping-rb?
To make my own ping software, I need to write my requirement and problems on a paper and find a way to solve them and find some packages to use them in my project. There was my problems:
How to ping a system?
How to make CLI Tool?
How can I improve the readability of my tool?
I search my problems on the internet, and I found perfect libraries for my case in rubygems site comprise:
Net-Ping
Optparse
CLI-UI
Colorize
Net-Ping: The net-ping library provides a ping interface for Ruby. It includes separate TCP, HTTP, LDAP, ICMP, UDP, WMI (for Windows) and external ping classes.
Optparse: OptionParser is a class for command-line option analysis.
NOTE: In my case, I used Optparse. It's so good!
CLI-UI: Terminal UI framework.
Colorize: Extends String class or add a ColorizedString with methods to set text color, background color and text effects.
Installation
If you want to install Ping-rb on your computer, first you have to installed Ruby language on your computer, then open your terminal or command prompt (CMD), after that enter this command in your terminal or CMD:
$ gem install ping-rbHow to use?
If you want to use Ping-rb, but you don't know how to use it, you can use help option.
$ ping-rb -a
or
$ ping-rb --aid
or
$ ping-rb --helpAfter that you will see all options looks like this:
Explain: Send ICMP ECHO_REQUEST to network hosts
VERSION 0.2.3
------------------------------------------------
Author: Meisam Heidari
Github: https://github.com/Mr-Fox-h
Gitlab: https://gitlab.com/mr-fox-h
Bitbucket: https://bitbucket.org/mr-fox-h
------------------------------------------------
-e, --external NAME External ping
-h, --http NAME HTTP ping
-t, --tcp NAME TCP ping
-u, --udp NAME UDP ping
--external-loop NAME External ping (LOOP MODE)
--http-loop NAME HTTP ping (LOOP MODE)
--tcp-loop NAME TCP ping (LOOP MODE)
--udp-loop NAME UDP ping (LOOP MODE)
--verbose-e NAME Verbose output for External ping
--verbose-h NAME Verbose output for HTTP ping
--verbose-t NAME Verbose output for TCP ping
--verbose-u NAME Verbose output for UDP ping
-a, --aid, --help Print this help
Source code
The Source code is on my github account:


