Giter Site home page Giter Site logo

whatportis's Introduction

whatportis

image

image

image

image

image

It's a common task to search the default port number of a service. Some ports are available in the /etc/services file, but the list is not complete and this solution is not portable.

Whatportis is a simple tool that downloads the Iana.org database and uses it to explore the official list of ports.

Usage

Whatportis allows you to find what port is associated with a service:

$ whatportis redis
+-------+------+----------+---------------------------------------+
| Name  | Port | Protocol | Description                           |
+-------+------+----------+---------------------------------------+
| redis | 6379 |   tcp    | An advanced key-value cache and store |
+-------+------+----------+---------------------------------------+

Or, conversely, what service is associated with a port number:

$ whatportis 5432
+------------+------+----------+---------------------+
| Name       | Port | Protocol | Description         |
+------------+------+----------+---------------------+
| postgresql | 5432 | tcp, udp | PostgreSQL Database |
+------------+------+----------+---------------------+

You can also search a pattern without knowing the exact name by adding the --like option:

$ 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 |
+----------------+-------+----------+-----------------------------------+

Installation

$ pip install whatportis

Database Sync

Whatportis uses a local JSON file (~/.whatportis_db.json) to explore the list of ports. The first usage will create it for you, then you can use the --update option to synchronize it :

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

JSON output

You can display the results as JSON, using the --json option :

$ whatportis 5432 --json
[
    {
        "name": "postgresql",
        "port": "5432",
        "protocol": "tcp, udp",
        "description": "PostgreSQL Database"
    }
]

REST API

Whatportis can also be started as a RESTful API server. This feature is not enabled by default, you must install an extra package :

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

The endpoints are /ports for the whole list (can be long) and /ports/<search> to search a specific port :

$ 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"}]}

You can use the ?like parameter to search a pattern.

whatportis's People

Contributors

brouberol avatar iximeow avatar ncrocfer avatar timofurrer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

whatportis's Issues

Store service names and ports in a JSON/YAML file?

IMHO, you should store the service name and ports in a human-readable serialized file, to lower the bar of contribution. Indeed, it seems waaay easier to submit a PR in the github web interface by adding a line in a JSON file, than adding a row in a sqlite file.

What do you think? I'd be more than happy to do this in a PR, in the format of your choice.

Update pinned requirements?

Howdy,

Can you update your requirements similar to what theblackturtle did in their fork? https://github.com/theblackturtle/whatportis

Pip installing whatportis with other packages in an environment will tend to install the 0.8 version (as Pip tries to satisfy the older requirements specified in the whatportis setup.py).

Thanks.

The solution for can not find any port

Hi,this project is nice!

But when I install it by "pip install whatportis" or setup,I can't get any port(such as No ports found for 'redis').Then I try "whatportis --update",I got the error "UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 46: ordinal not in range(128)",and I found that "whatportis_db.json" is 0kb,so it seems that is encoding error(Maybe service-names-port-numbers.csv have some special characters).

Solution:
In "whatportis-script.py" add three lines:


#encoding=utf-8   //add utf-8
#!c:\python27\python.exe
# EASY-INSTALL-ENTRY-SCRIPT: 'whatportis==0.7','console_scripts','whatportis'
__requires__ = 'whatportis==0.7'
import re
import sys
from pkg_resources import load_entry_point
reload(sys)   //add
sys.setdefaultencoding('utf8')   //add

After that,It worked!
(Both win7 and debian have this problem)

AttributeError: 'Table' object has no attribute 'purge'

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.4 LTS
Release:	18.04
Codename:	bionic
$ pip3 -V
pip 20.1 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)
$ sudo pip3 install whatportis
$ whatportis redis
Database not found, doing first import...
Downloading https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv...
Populating database...
Traceback (most recent call last):
  File "/usr/local/bin/whatportis", line 8, in <module>
    sys.exit(run())
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/whatportis/cli.py", line 124, in run
    populate_db()
  File "/usr/local/lib/python3.6/dist-packages/whatportis/cli.py", line 63, in populate_db
    db.purge()
  File "/usr/local/lib/python3.6/dist-packages/tinydb/database.py", line 250, in __getattr__
    return getattr(self.table(self.default_table_name), name)
AttributeError: 'Table' object has no attribute 'purge'
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/foobar/.whatportis_db.json' mode='r+' encoding='UTF-8'>

Lync/Skype ports missing

Great tool!

can you please update the db with Skype for Business/Lync and Skype consumer ports.

Thx!

Python requests version

Hi, I am trying to figure out if there is a specific reason why whatportis uses requests==2.23.0 and not requests>=2.23.0?

"requests==2.23.0",

I've been using whatportis in one of our projects called reNgine, whatportis is an amazing tool out there, but this is causing conflict due to mismatched requests version.

Can't we use requests>=2.23.0?

Thanks ๐Ÿš€

--like doesnt work correctly

when using the like flag, no results are returned regardless of the input

whatportis 123
+------+------+----------+-----------------------+
| Name | Port | Protocol | Description |
+------+------+----------+-----------------------+
| ntp | 123 | tcp, udp | Network Time Protocol |
+------+------+----------+-----------------------+

whatportis 123 --like
No ports found for '123'

whatportis mysql --like
No ports found for 'mysql'

Show what application is listening on a local port

From the description "what service is listening on a given port" I would have expected whatport is to print the application which is running on that port on the current machine.

However it prints what the standardized or expected application on that port should be. For example, if I make a python application on my local machine which happens to listen on port 6379, whatportis will show 'redis'.

Can you make whatportis actually check the local machine port usage, fuser user -n tcp PORT or netstat -alnp | grep PORT, etc?

Or maybe the README could be amended to be clearer on this point.

How to contribute

Hey, cool tool! Is there anyway to contribute to this to fill the blanks about some port numbers that lana isn't storing information for?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.