
Whatportis : esplora l'elenco delle porte 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
È un compito comune cercare il numero di porta predefinito di un servizio. Alcune porte sono disponibili nel file :code:/etc/services, ma l'elenco non è completo e questa soluzione non è portabile.
Whatportis è un semplice strumento che scarica il database di Iana.org <http://www.iana.org/assignments/port-numbers>_ e lo utilizza per esplorare l'elenco ufficiale delle porte.
Whatportis ti permette di trovare quale porta è associata a un servizio:
.. code-block:: shell
$ whatportis redis
+-------+------+----------+---------------------------------------+
| Name | Port | Protocol | Description |
+-------+------+----------+---------------------------------------+
| redis | 6379 | tcp | An advanced key-value cache and store |
+-------+------+----------+---------------------------------------+
O, al contrario, quale servizio è associato a un numero di porta:
.. code-block:: shell
$ whatportis 5432
+------------+------+----------+---------------------+
| Name | Port | Protocol | Description |
+------------+------+----------+---------------------+
| postgresql | 5432 | tcp, udp | PostgreSQL Database |
+------------+------+----------+---------------------+
Puoi anche cercare un pattern senza conoscere il nome esatto aggiungendo l'opzione :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 utilizza un file JSON locale (:code:~/.whatportis_db.json) per esplorare l'elenco delle porte. Il primo utilizzo lo creerà per te, poi puoi usare l'opzione :code:--update per sincronizzarlo:
.. 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.
Puoi visualizzare i risultati in JSON usando l'opzione :code:--json:
.. code-block:: shell
$ whatportis 5432 --json
[
{
"name": "postgresql",
"port": "5432",
"protocol": "tcp, udp",
"description": "PostgreSQL Database"
}
]
Whatportis può essere avviato anche come server API RESTful. Questa funzionalità non è abilitata per impostazione predefinita, è necessario installare un pacchetto aggiuntivo:
.. 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)
Gli endpoint sono :code:/ports per l'intero elenco (può essere lungo) e :code:/ports/<search> per cercare una porta specifica:
.. 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"}]}
Puoi usare il parametro :code:?like per cercare un pattern.