[python]Test connection with socket module

This is the code snippet that checks if a specific port is listening on the target server or not, if the port could not be reached and does not exist the socket module throws a timeout exception or ConnectionRefusedError. from socket import socket, timeout as _timeout, AF_INET, SOCK_STREAM ERRORS = TimeoutError, ConnectionRefusedError, _timeout def has_service(address, … Continue reading [python]Test connection with socket module

[python]Record router information with mongodb

Introduction This is a lab demonstration on how to record cisco router's information to mongo database. Mongo database is very easy to learn for new developers who understand the json structure because the structure to insert data into the database is very json-like this is very easy to learn without knowing SQL syntax. I am … Continue reading [python]Record router information with mongodb

[python]Delete many by objectid using pymongo

I have multiple duplicated entries, I think this is the problem with NoSQL type of database, although easy to use it has no normalization method like the relational type database. So my mongo database have duplicated like this: These are the duplicates when I accidentally run the script multiple times with the same device info. … Continue reading [python]Delete many by objectid using pymongo

[python]Change interesting contents of a text file into dictionary

Introduction This exercise downloads the CHECKSUM file from the centos download page, the file downloaded is a temporary file and is destroyed once it is closed after used. The data read from the temporary file is then processed into a dictionary, the dictionary key is the filename and the value is the hash digest. Tempfile … Continue reading [python]Change interesting contents of a text file into dictionary

[python]Download file and use tqdm for progress bar.

Download file with requests To download the file from web with requests module is the easiest, you just need to turn on stream while using get method. Then download the file chunk by chunk by using the iter_content method. Here is the example code on how to download file with requests. import requests from pathlib … Continue reading [python]Download file and use tqdm for progress bar.