Coder Social home page Coder Social logo

nick3499 / whois_cli Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 211 KB

Using PyPI's ipwhois package to get whois data which is then displayed to a terminal emulator

License: MIT License

Python 100.00%
dictionary whois-lookup json-data ipwhois terminal-app ipv4-address forloops argv python3-application

whois_cli's Introduction

whois_cli

This repo is made available under MIT license (see LICENSE).

whois_cli.py was tested in a Unix-like terminal emulator running Bash in Ubuntu 18.04.

pip was used for package management.

screen capture

requirements.txt

Note:

  1. since specific Python libraries may be used system-wide in Ubuntu—to be safe—a virtual environment is required.
  2. if Ubuntu is using pip and pip2 for Python 2 package management, then pip3 will be the required package manager.

To install required dependencies:

$ pip install -r requirements.txt

dnspython==1.16.0
ipwhois==1.1.0

The sys.argv method will also be imported.

from ipwhois import IPWhois
from sys import argv

whois_cli.py

IPWhois(argv[1]).lookup_rdap()

ipwhois.IPWhois : is the base class for wrapping whois lookups.

sys.argv[1] : gets first command line argument passed to whois_cli.py or the IPv4 number.

IPWhois.lookup_rdap() : became the recommended lookup method, since RDAP provides more efficient, higher quality whois data.

_objs = w["objects"] : indicates that the objects dictionary within the whois data will be stored in the objs variable.

_asn = {
    "asn": "ASN",
    "asn_cidr": "CIDR",
    "asn_country_code": "Country code",
    "asn_date": "Date",
    "asn_description": "Description",
    "asn_registry": "Registry"
}

The dictionary above contains ASN keys with their associated values for capitalized string syntax.

try:
    for k, v in net_remarks.items():
        print(f'{cyan}{v}{end}: {_net["remarks"][0][k]}')
except TypeError:
    print(f'{cyan}{v}{end}: n/a')

In the for loop above, a try/except block was used to handle None returns. n/a strings replace None returns.

Color Formatting

red = "\x1b[0;31m"
cyan = "\x1b[0;36m"
end = "\x1b[0m"

Parts of color formatting syntax for text display in the terminal emulator were stored in variables (see above).

print(f'{cyan}{v}{end}: {_net["remarks"][0][k]}')

{cyan}{v}{end} demonstrates the use of f-string expressions to format text colors.

ko-fi

whois_cli's People

Contributors

nick3499 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

woounnan

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.