Posts

Showing posts with the label Networking

[ Level 1 ] Install libraries for juniper vpn in 13.10

$ sudo apt-get remove sudo apt-get remove openjdk-6-jdk icedtea-6-plugin $ sudo apt-get install openjdk-7-jdk icedtea-7-plugin $ sudo apt-get install openjdk-7-jre:i386 $ sudo apt-get install libstdc++6:i386 lib32z1 lib32ncurses5 lib32bz2-1.0 libxext6:i386 libxrender1:i386 libxtst6:i386 libxi6:i386 Wish this helps. regards, Stanley Huang

[ Level 3 ] The script for creating virtualbox envrionment (Ubuntu 12.04) with lauch new OS image.

In my company, I need to test it when I build a new image. Therefore I have to setup my testing environment for integration test. I wrote a script to automatically setup the environment from new install Ubuntu. The steps are: 1. Download and setup tftp server. 2. Download and setup dhcp server with netboot option. 3. Install virtualbox. After that you could create a VM then choose netboot. (the first interface must connect to tap0 to get boot server information) #!/bin/bash ######## utilities ######## _getTasks() { indent="$1" cat $0 | grep '()' | grep -v "^_" | grep "^[^ ]" | cut -d'(' -f1 | sed -e "s/^/$indent/" } _showUsage() { indent=" " cat <<EOF Usage: $0 task Ex. $0 `_getTasks | head -1` tasks: ${indent}[ all ] `_getTasks "$indent"` EOF } _die() { echo "$1" exit ${2:-1} } _checkID() { uid=`id | cut -d'(' -f1 | cut -d'=' -f2` [ $uid -ne ...

[ Level 2 ] Connect pool for ssh.

If you want to use the concept "connection pool" for ssh, you could try the following sample. #!/bin/bash # # You might need to modify sshd_config with the following attributes: # # MaxStartup 200 # MaxSessions 200 # [ "$1" == "-d" ] && set -vx && shift control_master="$1" && [ "$control_master" != "false" ] && control_master=true username="$2" && [ -z $username ] && username=stanley remote_host="$3" && [ -z $remote_host ] && remote_host=127.0.0.1 cmd1="$4"&& [ -z $cmd1 ] && cmd1=ls control_master_option="" client_cmd="/tmp/a.sh" buildControlMaster() { if $control_master then ssh -N -o "ControlMaster auto" -o "ControlPath ~/.ssh/master-$username@$remote_host" $username@$remote_host & fi } createClientCmd() { mkdir -p /tmp/add rm /tmp/add/* $client_cmd if $c...

[Level 3] Network Simulator

Memo it: 1. openWNS: www.openwns.org/Wiki 2. ns-3: www.nsnam.org , ns-3 provides python API to use. Wish this helps. regards, Stanley Huang

[Level 3] How to setup Juniper VPN in Ubuntu 64 bit environment.

A good sample to demo how to setup Juniper VPN in Ubuntu 64 bit environment. http://wireless.siu.edu/install-ubuntu-64.htm Wish this helps. regards, Stanley Huang

[Level 2] How to enable VNC server in Ubuntu 10.04

How to enable VNC server in Ubuntu 10.04, please refer here . Wish this helps. regards, Stanley Huang

[Level 2] Juniper vpn for ubuntu

If you need to setup the vpn on Ubuntu, you could refer to the following 2 links: http://mad-scientist.us/juniper.html http://holyarmy.org/2009/06/vpn-on-ubuntu-linux-with-juniper-network-connect/ Wish this helps. regards, Stanley Huang

[Level 3] The bonding info of Linux

The bonding info of Linux, click here for more detail. Wish this helps. regards, Stanley Huang

[Level 1] Install telnetd in Ubuntu 10.04

Install telnetd in Ubuntu 10.04: # sudo su # apt-get install openbsd-inetd # echo "telnet stream tcp nowait root /usr/sbin/tcpd /usr/sbin/in.telnetd" >> /etc/inetd.conf # /etc/init.d/openbsd-inetd restart Wish this helps. regards, Stanley Huang

[Level 2] python oui lookup

$ sudo apt-get -y install python-netaddr ... $ cd /usr/share/pyshared/netaddr/eui $ sudo python ./ieee.py downloading latest copy of http://standards.ieee.org/regauth/oui/oui.txt downloading latest copy of http://standards.ieee.org/regauth/oui/iab.txt $ python >>> from netaddr import * >>> mac = EUI('bc:ae:c5:3b:fc:5e') >>> print mac.oui.registration().org ASUSTek COMPUTER INC. Wish this helps. regards, Stanley Huang

[Level 2] Enable wireless of network-manager in Ubuntu 11.04

Once you upgrade Ubuntu from 10.04 to 11.04, and you will find out the network-manager won't manage wireless any more. But you still could change NetworkManager.conf to enable it. # sudo vi /etc/NetworkManager/NetworkManager.conf and change "managed" attribute from "false" to “true“ and restart it. # sudo /etc/init.d/network-manager restart Wish this helps. regards, Stanley Huang

[Level 2] How to connect wireless ap by command in Ubuntu.

How to connect wireless ap by command in Ubuntu? You can use two commands, 'iwlist', 'iwconfig'. # iwlist --help Usage: iwlist [interface] scanning [essid NNN] [last] [interface] frequency [interface] channel [interface] bitrate [interface] rate [interface] encryption [interface] keys [interface] power [interface] txpower [interface] retry [interface] ap [interface] accesspoints [interface] peers [interface] event [interface] auth [interface] wpakeys [interface] genie [interface] modulation # iwlist wlan0 scanning essid ap_name # iwconfig --help Usage: iwconfig [interface] interface essid {NNN|any|on|off} interface mode {managed|ad-hoc|master|...} interface freq N.NNN[k|...

[Level 3] Firewall in Ubuntu.

install gui tool for ufw # apt-get -y install gufw # gufw use command(ufw) to setting firewall, and the config file in in /lib/ufw/user.rules # ufw deny from any to any port 22 # ls -al /lib/ufw/user.rules -rw-r----- 1 root root 1405 2011-04-01 17:36 /lib/ufw/user.rules # ufw delete deny from any to any port 22 # ls -al /lib/ufw/user.rules -rw-r----- 1 root root 1263 2011-04-01 17:36 /lib/ufw/user.rules my setting history (reference only): ufw disable ufw default deny ufw logging ON ufw enable ufw allow 22/tcp ufw allow proto tcp from 192.168.1.0/24 to 192.168.1.101 port 80 use iptables command: #!/bin/bash MY_IP=192.168.100.101 # Flushing all rules and chains iptables -F iptables -X # Setting default policy iptables -P INPUT DROP iptables -P OUTPUT ACCEPT iptables -P FORWARD DROP # Allow traffic on loopback iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT # Allow ssh for in/out iptables -A INPUT -p tcp -s 0/0 -d $MY_IP --sport 513:65535 --dport 22 -m state...

[Level 2] get broadcast by Python

I wrote a python script to get broadcast by giving ip and netmask. And I use "lambda" and "map" function to shorten my code, so it's also a good sample for you to study map function. More information please refer here . The sample code is as the following: #!/bin/env python def getBroadcast(self, ip=None, netmask=None): if not ip or not netmask: return None ip = ip.split('.') netmask = netmask.split('.') for n in range(0,4): if netmask[n] == '0': break bc = (map(lambda a, b: str(int(a, 10)&int(b,10)), ip[0:n]+['255']*(4-n), netmask[0:n]+['255']*(4-n))) if n > 1: bc[n-1] = str(int(bc[n-1]) + (255 - int(netmask[n-1]))) return '.'.join(bc) print getBroadcast('192.168.10.1','255.255.254.0') Result: 192.168.11.255 Wish this helps. regards, Stanley Huang

[Level 2] Get ether list by Python in Ubuntu.

#!/bin/env python def getEtherList(): return [x.strip() for x in \ os.popen("ifconfig -a | \ grep Link | grep '^[^ ]' | \ grep -v lo | awk '{print($1)}'")\ .readlines()] print getEtherList() Wish this helps. regards, Stanley Huang

[Level 2] Implement prefix and netmask transfer with Python.

Sometimes, you want to transfer between netmask and prefix setting. You can use the following sample script which is written by Python. #!/bin/env python def transferPrefix2Netmask(self, prefix): netmask = '' nLeadingFF = prefix / 8 netmask += '.'.join(['255']*nLeadingFF) if nLeadingFF != 4: netmask += '.' + str(256-2**(8-prefix%8)) nSuffix00 = 3 - nLeadingFF if nLeadingFF < 3: netmask += '.' + '.'.join(['00']*nSuffix00) return netmask def transferNetmask2Prefix(self, netmask): prefix = 0 left = 0 for i in netmask.split('.'): if i == '255': prefix += 8 else: left = int(i) break if left != 0: for n in range(7, 0, -1): prefix += 1 if left - 2 ** n == 0: break ...

[Level 2] How to reset interface seq. no in Ubuntu

If you want to reset the seq. no of interface. You can remove the record in /etc/udev/rules.d/70-persistent-net.rules. Wish this helps. regards, Stanley Huang

[Level 3] Networking library for Python -- Scapy.

One networking library for python called 'Scapy', is worth for you to try. http://www.secdev.org/projects/scapy/index.html Wish this helps. regards, Stanley Huang

How to setup your wireless interface to auto connect to ap in Ubuntu?

How to setup your wireless interface to auto connect to ap in Ubuntu? You can set the config in /etc/network/interface like below: wlan0 auto iface wlan0 inet dhcp wireless-essid your_essid wireless-key your_essid_passphrase wireless-channel your_essid_channel Wish this helps. regards, Stanley Huang

[Level 2] How to detect port with python script.

If you want to detect port, you can use socket module to do it. #!/bin/env python import os, sys import socket def detectPort(PORT):     # Echo server program     import socket     HOST = ''     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)     try:         s.bind((HOST, PORT))         return_code=1     except:         return_code=0     s.close()     return return_code if __name__ == '__main__':   for PORT in [80,81,82,8000,8080,3306,3307]:     if detectPort(PORT): print PORT Wish this helps. regards, Stanley Huang