Saving linux tcpdump captures to File

For capturing all the packets on interface

#tcpdump -i <interface> -w <filename>.pcap

Example:

#tcpdump -i eth1 -w capture.pcap

Limiting captures to number of packets

#tcpdump -i <interface> -c <count> -w <filename>.pcap

Example:

#tcpdump -i eth1 -c 1000 -w capture.pcap

Only capturing packet with destination ip

#tcpdump -i <interface> -c <count> -w <filename>.pcap dst <ip>

Example:

#tcpdump -i eth1 -c 1000 -w capture.pcap dst 192.168.1.120

Capturing packets with destination port

#tcpdump -i <interface> -c <count> -w <filename>.pcap dst port <port>

Example:

#tcpdump -i eth1 -c 1000 -w capture.pcap dst port 80

Capturing packets where host is the source or destination

#tcpdump -i <interface> -c <count> -w <filename>.pcap <host>

Example:

#tcpdump -i eth1 -c 1000 -w capture.pcap host 192.168.1.120

 

Later these can be viewed on a wireshark or any other ip packet analyzer which support .pcap files.

[Read More: “Tcpdump usage examples” by rationallyPARANOID]

IP Subnetting Quick Cheat Sheet

If you work in IP Networks then you already know how IP subnetting works and most likely remembers all the subnets… this tutorial is not for you.

Few years back when I was doing my CCNA, I had a good basics of IP subnetting and I knew all the binary calculation which is the first step for understanding through which I was able to calculate subnets, hosts range , etc. However, it used to take me minutes to calculate. So, I had to make something simple for me to remember and I made the following table.

Note: I may not be the only one who created this table , there may be thousands of versions similar to it. But it worked for me. So, it may work for the person who is new to IP just like me when I was trying to polish my skills.

Table-1

subnettable1

Table-2

subnettable2

Example:

Suppose we have an IP address : 10.10.10.163/27

We need to find out the Subnet Mask, Network Address, Broadcast Address and Range of Hosts.

Step 1:

In Table-1 we see /27 has a subnet of ‘224’, we know that /27 is in the last octet so,

Subnet mask=  255.255.255.224

Step 2:

Now from the same Table-1 we see that Number of IPs will be 32 per subnet.

But we know that we have to subtract 2 IP address from 32, one for Network Address and other for Broadcast Address.

No of Host in 27 Network = 32-2= 30

Step 3:

We see Table-2 and go through /27 column, we find that out IP last octet .163 lies in the range between ‘160’ and ‘192’.

So, For network address we always take the lowest one so,

Network Address= 10.10.10.160

For Broadcast address , we will subtract 1 from 192.

Broadcast Address= 10.10.10.191

Step 4:

Range Host of addresses is now easy to find.

We know our Network Address= 10.10.10.160 & Broadcast Address= 10.10.10.191

Range of Hosts= 10.10.10.161 – 10.10.10.190

Ok, That was easy and I know subnetting Class-3 is always easy!

Python: How to create zip of files?

Download Code From Here

import zipfile
import time
import os

def create_zip(zip_filenames):
  zipped_name='ZipFile'+str(time.strftime("%m%d%Y_%H%M%S"))+'.zip'
  print "Creating ", zipped_name
  zf = zipfile.ZipFile(zipped_name, mode='w')

for filename in zip_filenames:
  try:
    print "Adding",filename,"in",zipped_name
    zf.write(filename)
  except:
    ":::ERROR::: Unable to add file to zipped file"
     print "Created Zipped File",zipped_name 
     zf.close()

def remove_files(remove_filesnames):
  for filename in remove_filesnames:
    print "Removing", filename
    os.remove(filename)


if __name__=="__main__":

  filenames= ['syspreset001','syspreset0161.prst','zip']
  create_zip(filenames)
  remove_files(filenames)

Python: How to download file using FTP?

Download the following script from Here.

####
#Download File with FTP.
#Download_System requires two variables HOST & directory & filename
####

import ftplib
import sys

#Host and Gets the Filename of the Preset
def Download_System(HOST,directory,filename):
  try:
    filename_get=filename
    directory_get=directory
    ftp_download=ftplib.FTP(HOST) #opens Ftp Connection to the HOST
    ftp_download.login( "root", "root") #username, password
    ftp_download.cwd(directory_get) #Change Directory to file directory
    localfile=open(filename_get,'wb') #Open Localfile to write
    ftp_download.retrbinary("RETR " + filename_get, localfile.write) #Get the Filname in Binary
  except Exception as e:
    print ":::ERROR:::: " +str(e)

if __name__=="__main__":
  HOST='Host'
  Filename='Filename'
  Directory='Change Directory Here'
  Download_System(HOST,Directory,Filename)

Free File synchronization software for Windows

Ghacks has a good article written by Martin Brinkmann for What’s the best free file synchronization software for Windows? The article has around 8 listing of free synchronization software ranging from Light to full featured.

 

2015-11-02_152800

 

I downloaded 5 of them and found SyncBack Free best among them, which has all the features that is requirement of a personal PC, scheduling works on Windows 10 (some of the software such as Fbackup had issues) , compression and encryption, filtering based on file and lot more options.

Learning Python GUI using Tkinter

As I wanted to learn the python GUI,
I searched on internet and found these very nice tutorials on how to built GUI using Tkinter library of python. There are few more GUI libraries available on the internet as you may be aware such as wxpython, but I found Tkinter suitable for my needs and easy to work with. I started learning from UsingPython , it also has a good basic python tutorials if you want to have a refresher course.

pythoncourse

The other one was the Python Course which also has some really nice examples and a bit more than using python but both are good and you can start from either one.

Following are library references which are handy to know what things you can change using arguments.

It’s like snapchat, but for files!

A service that I fell in love for file transfers!file-io

Simply upload a file, share the link, and after it is downloaded, the file is completely deleted. For added security, set an expiration on the file and it is deleted within a certain amount of time, even if it was never downloaded.

 

Configuring VLANs in Linux

Turn off the Network Manager

#chkconfig NetworkManager off

goto directory “/etc/sysconfig/network-scripts/” and edit ifcfg-eth0 or ifcfg-eth1.

#cd /etc/sysconfig/network-scripts/
#vi ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
HWADDR=00:0C:29:CA:19:29
HOTPLUG=no
IPADDR=10.10.1.230
PREFIX=24
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
IPV6_AUTOCONF=no
NAME="Ethernet1"
VLAN=yes

For creating VLAN with ID=300

#cp ifcfg-eth0 ifcfg-eth.300          //copy file and rename it to eth.vlanid
#vi ifcfg-eth.300
DEVICE=eth0.300
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
HWADDR=00:0C:29:CA:19:29
HOTPLUG=no
IPADDR=10.10.2.230
PREFIX=24
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
IPV6_AUTOCONF=no
NAME="VLAN300"
VLAN=yes

Then

#service network restart

You can create more VLANs by creating more files “ifcfg-eth0.<VLANID>” and replacing it with VLAN ID.