In August 2014, more than 300,000 people registered for the first offering of the Introduction to Linux course. This popular Massive Open Online Course (MOCC) is taught by the Linux Foundation, and hosted on edx. The same course starts again on January 5, 2015. The course is designed for people who have limited or no previous exposure to Linux.
Following on from SSH and SFTP with Paramiko & Python, I recently had the need to gain a remote SSH server’s fingerprint and hostkey for verification purposes. This is achievable through setting up a socket, and then applying paramiko.Transport over our established socket. First, we include the various bits and pieces we’ll need:
To run specific part or exclude specific part in a playbook we an use tags attrubute.
Here is my example playbook with name tags_example.yml:
- hosts: all
- name: Hello
shell: "echo hello"
- name: Bye
shell: "echo bye"
In above playbook we have two tasks Hello and Bye with tags hello and bye tags respectively.
To execute above playbook use following command:
Starting from kernel 2.6.24, Linux supports 6 different types of namespaces. Namespaces are useful in isolating processes from the rest of the system, without needing to use full low level virtualization technology.
imaplib is a great library for handling IMAP communication. It supports both plaintext IMAP and IMAP over SSL (IMAPS) with ease. Connecting to an IMAP server is achieved as follows:
Following on from performing basic DNS Lookups in Python, it’s relatively trivial to begin testing DNS Block Lists/Real Time Black Lists for blocked mail server IP addresses. To assist in preventing spam, a number of public and private RBLs are available. These track the IP addresses of mail servers that are known to produce spam, thus allowing recipient mail servers to deny delivery from known spammers.
dnspython provides a detailed interface into DNS. In its simplest form, it’s possible to perform queries in only a couple of lines of code. Here’s a commented example:
import dns.resolver #import the module myResolver = dns.resolver.Resolver() #create a new instance named 'myResolver' myAnswers = myResolver.query("google.com", "A") #Lookup the 'A' record(s) for google.com for rdata in myAnswers: #for each response print rdata #print the data
The results in my case are:
By using nc(Netcat) command we can check if a port in remote machine is opened or closed.
Here is an example to check if remote port is opened or closed:
STATUS=$(nc -z you_remote_host 80 ; echo $?)
if [ $STATUS -eq 0 ]
echo "Port is opened"
echo "Port is opened"
To get previous command status in bash use “$?” variable.
echo $? will return zero if previous command is success & if its non zero it indicates failure.
$ ls ; echo $?
Output of the above command is list of files, directories and next line it will return number.
We can use condition for check if previous command is success or failure: