my code stock.com

get allied telesyn route firewall session.

Snippet options

Download: Download snippet as get_fwsessionpy.py.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

#!/usr/bin/env python
#
#
import sys
import re
import telnetlib

HOST = sys.argv[1]
TM_OUT = 3

try:
   tn = telnetlib.Telnet(HOST)
   tn.read_until("login: ",TM_OUT)
   tn.write("username\n")
   tn.read_until("Password: ",TM_OUT)
   tn.write("password\n")
   tn.read_until(">",TM_OUT)
   tn.write("set tty page=off\n")
   tn.read_until(">",TM_OUT)
   tn.write("show firewall policy\n")
   buf=tn.read_until(">",TM_OUT)
   tn.write("logout\n")
   tn.close()
except:
   sys.exit(1)

pat = re.compile('Number of Active Sessions ......... ([0-9]+)' ,re.M)
res = re.search(pat,buf)
sys.stdout.write(res.group(1))

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.