Showing posts with label network tool. Show all posts
Showing posts with label network tool. Show all posts

Saturday, January 14, 2012

Scapy - Easy packet generation

Scapy is a python command based packet generation tool. It help to create packet very easily. It has full control over protocol stack. We can alter all the bits in the packet and modify any packet according to our wish.

installing scapy:
                          $ wget scapy.net
                          $ unzip scapy-latest.zip
                          $ cd scapy-2.*
                          $ sudo python setup.py install

starting scapy:
                         $ scapy



Documentation present at : www.dirk-loss.de/scapy-doc/Scapy.pdf


Sample code: [ICMP packet generation ]
                     
root@bt:~# scapy
WARNING: No route found for IPv6 destination :: (no default route?)
Welcome to Scapy (2.1.0)
>>> a= ICMP()
>>> b= IP()
>>> c=Ether()
>>> d=c/b/a

>>> d.display()
###[ Ethernet ]###
  dst= ff:ff:ff:ff:ff:ff
  src= 00:00:00:00:00:00
  type= 0x800
###[ IP ]###
     version= 4
     ihl= None
     tos= 0x0
     len= None
     id= 1
     flags=
     frag= 0
     ttl= 64
     proto= icmp
     chksum= None
     src= 127.0.0.1
     dst= 127.0.0.1
     \options\
###[ ICMP ]###
        type= echo-request
        code= 0
        chksum= None
        id= 0x0
        seq= 0x0
>>> send (d)       // sending the packet d into network


## send () is used when we are injecting packet at layer3.
and if we want to send packet with modification at layer 2 entry then we will use sendp() to send packet.
otherwise we will get a warning message. 
      >>> send(ether/ip/icmp)
WARNING: Mac address to reach destination not found. Using broadcast.
.
Sent 1 packets.


for more information

enjoy coding.. :) B-)

Monday, September 5, 2011

a simple code for ns2

following code is a good example to understand how to write a simple tcl script for ns2 simulation.

#simulator object
set ns [new Simulator]

#colouring the class 1 packet
$ns color 1 Blue
$ns color 2 Red

#open a file to write and attaching it to ns object
set nf [open out.nam w]
$ns namtrace-all $nf

#process finish called at the last
proc finish {} {
          global ns nf
          $ns flush-trace
          close $nf
          exec nam out.nam &
          exit 0
           }

#creation of node       
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

#creation of link
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
#we created a stochastic fair queu between 2 and 
$ns duplex-link $n2 $n3 0.5Mb 10ms SFQ

#for layout of links
$ns duplex-link-op $n0 $n2 orient right-down     
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right

#setting udp agent
set udp0 [new Agent/UDP]
set udp1 [new Agent/UDP]

$ns attach-agent $n0 $udp0
$ns attach-agent $n1 $udp1

#setting traffic agent then it will attach to udp agent
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval 0.005
$udp0 set class_ 1
#attaching cbr agent to udp agent
$cbr0 attach-agent $udp0

set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval 0.005
$udp1 set class_ 2
$cbr1 attach-agent $udp1

#this is sink
set null3 [new Agent/Null]
$ns attach-agent $n3 $null3

$ns connect $udp0 $null3
$ns connect $udp1 $null3

# to make a queu at a node
$ns duplex-link-op $n3 $n2 queuePos 0.5
#monitor a queu

$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
$ns at 1.5 "$cbr1 start"
$ns at 4.0 "$cbr1 stop"
#$ns duplex-link-op $n0 $n1 orient right-down
#$ns duplex-link-op $n1 $n2 orient right
#$ns duplex-link-op $n2 $n0 orient right-up

$ns at 5.0 "finish"
$ns run

save this with any *.tcl name and run it simply #ns *.tcl
.... enjoy coding

Saturday, September 3, 2011

Installation of NS2 in ubuntu

I tried to install ns2 and downloaded its code to install it in my ubuntu10.10 system but it was tedious task.
And then i found that following steps were the most simplest way to install ns2.

step 1: make sure that u don't have any previous installation of ns2.

step 2: export the key for ppa
           #sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B3F3334F

step 3: add ppa to your source. You can get this file /etc/apt/source.list. Simply append these line to source.list file.
       
             deb http://ppa.launchpad.net/wouterh/ppa/ubuntu karmic main

             deb-src http://ppa.launchpad.net/wouterh/ppa/ubuntu karmic main

step 4: now reload your apt-cache 
            #sudo apt-get update 
            or simply reload your synaptic package manager

step 5: install ns2
             #sudo apt-get install ns nam xgraph
      now ns2 installed.

Test run:
download sample code that is tcl file.
run this code
         # ns example1b.tcl

done......  enjoy coding.. 
         
           
           

Saturday, August 13, 2011

installing arp-sk

arp-sk is basically an ARP Traffic Generation Tool. It’s quite old but still very useful! There are 2 basics mode:
– who-has: build a request ARP message.
– reply: build a reply ARP message (default)

download arp-sk from
http://sid.rstack.org/arp-sk/

it works on libnet 1.1. you can download it from:
http://linux.softpedia.com/get/Programming/Libraries/Libnet-10275.shtml

to install libnet 1.1.2.1
1. $tar xvzf libnet-1.1.2.1.tar.gz
2. $./configure
3. $make & make install

to install arp-sk
1. $tar xzvf arp-sk-0.0.16.tgz
2. $cd arp-sk
3. $./configure
4. $make & make install

use arp-sk
$arp-sk <mode> <option>

for more help