
Whatportis : explorer la liste des ports de l'IANA
.. image:: https://github.com/opencve/opencve/workflows/Tests/badge.svg :target: https://github.com/ncrocfer/whatportis/actions/workflows/tests.yml
.. image:: https://badge.fury.io/py/whatportis.svg :target: https://pypi.python.org/pypi/whatportis/
.. image:: https://img.shields.io/badge/python-3.6%2B-blue.svg :target: https://pypi.python.org/pypi/whatportis/
.. image:: https://img.shields.io/github/license/ncrocfer/whatportis.svg :target: https://github.com/ncrocfer/whatportis/blob/master/LICENSE.txt
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/python/black
C'est une tâche courante de rechercher le numéro de port par défaut d'un service. Certains ports sont disponibles dans le fichier :code:/etc/services, mais la liste n'est pas complète et cette solution n'est pas portable.
Whatportis est un outil simple qui télécharge la base de données Iana.org <http://www.iana.org/assignments/port-numbers>_ et l'utilise pour explorer la liste officielle des ports.
Whatportis vous permet de trouver quel port est associé à un service :
.. code-block:: shell
$ whatportis redis
+-------+------+----------+---------------------------------------+
| Name | Port | Protocol | Description |
+-------+------+----------+---------------------------------------+
| redis | 6379 | tcp | An advanced key-value cache and store |
+-------+------+----------+---------------------------------------+
Ou, inversement, quel service est associé à un numéro de port :
.. code-block:: shell
$ whatportis 5432
+------------+------+----------+---------------------+
| Name | Port | Protocol | Description |
+------------+------+----------+---------------------+
| postgresql | 5432 | tcp, udp | PostgreSQL Database |
+------------+------+----------+---------------------+
Vous pouvez également rechercher un motif sans connaître le nom exact en ajoutant l'option :code:--like :
.. code-block:: shell
$ whatportis mysql --like
+----------------+-------+----------+-----------------------------------+
| Name | Port | Protocol | Description |
+----------------+-------+----------+-----------------------------------+
| mysql-cluster | 1186 | tcp, udp | MySQL Cluster Manager |
| mysql-cm-agent | 1862 | tcp, udp | MySQL Cluster Manager Agent |
| mysql-im | 2273 | tcp, udp | MySQL Instance Manager |
| mysql | 3306 | tcp, udp | MySQL |
| mysql-proxy | 6446 | tcp, udp | MySQL Proxy |
| mysqlx | 33060 | tcp | MySQL Database Extended Interface |
+----------------+-------+----------+-----------------------------------+
.. code-block:: shell
$ pip install whatportis
Whatportis utilise un fichier JSON local (:code:~/.whatportis_db.json) pour explorer la liste des ports. La première utilisation le créera pour vous, puis vous pouvez utiliser l'option :code:--update pour le synchroniser :
.. code-block:: shell
$ whatportis --update
Previous database will be updated, do you want to continue? [y/N]: y
Downloading https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv...
Populating database...
14145 ports imported.
Vous pouvez afficher les résultats au format JSON, en utilisant l'option :code:--json :
.. code-block:: shell
$ whatportis 5432 --json
[
{
"name": "postgresql",
"port": "5432",
"protocol": "tcp, udp",
"description": "PostgreSQL Database"
}
]
Whatportis peut également être démarré en tant que serveur d'API RESTful. Cette fonctionnalité n'est pas activée par défaut, vous devez installer un paquet supplémentaire :
.. code-block:: shell
$ pip install whatportis[server]
$ whatportis --server localhost 8080
* Serving Flask app "whatportis.server" (lazy loading)
* Environment: prod
* Debug mode: off
* Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
Les endpoints sont :code:/ports pour la liste complète (peut être long) et :code:/ports/<search> pour rechercher un port spécifique :
.. code-block:: shell
$ curl http://127.0.0.1:8080/ports/3306
{"ports":[{"description":"MySQL","name":"mysql","port":"3306","protocol":"tcp, udp"}]}
$ curl http://localhost:8080/ports/redis
{"ports":[{"description":"An advanced key-value cache and store","name":"redis","port":"6379","protocol":"tcp"}]}
Vous pouvez utiliser le paramètre :code:?like pour rechercher un motif.