Tuesday 10 May 2016

Python: how to telnet MSAN Cabinet and change port configuration




python is amazing usable programming langue i saw ever,



 well, this topic about the challenge that i faced in my work @TEData ( biggest ISP in egypt) we have a repeated problem that happened when the TE(Telecom Egypt) specialist assign the new ADSL user to the TEData Vlan ( vlan number look like 405 - 420 ....etc) but he assign customer to another vlan by mistake so our customer can't reach has ADSL service plus customer showing the another ISP (like Nour - Orange - Vodafone) portal 
this case usually escalated to us to re-assign the customer  to the correct Vlan, we have a full queue by the same cases , i written a python script that offer the sample solution it works as :

1- Telnet the huawei MSAN Cabinet 5600T
2- looking for the correct stacking Vlan
3- check if the desired port is configured OR not.
4- if not configured send message "port not configured"close telnet session 
5- if configured check configuration of the port desired 
6- if the configuration is OK send message "Everything is OK& no problem found "
7- else: replace the correct vlan by the port configuration 
8- send message    "the vlan changed from "wong number " to the "correct vlan number"
9-close telnet session 


I'll upload the code soon  you can check the below part of code :




import telnetlib

import sys
import time
import re

#####################################################################################################
############ scritp written By Mohamed El Hosseny to correct the Bit streem Issue exclusive fot TEDATA company
############ Mohamed.hosseny@outlook.com
############ Python V2.7
#####################################################################################################
#------Telne&login-------#
HOST = int (raw_input("Enter Host IP:"))
user = chr (raw_input("Enter userName:"))
password = chr (raw_input("Enter password:"))
port = int (raw_input("Enter port look like 1/1/1 :"))

tn = telnetlib.Telnet(HOST)
tn.read_until("name:",5)
tn.write(user)
tn.read_until("sword:",5)
tn.write(password)
tn.read_until(">",10)#incase the cbenit Hostname end by E NOT EG

    #----------Run_Script --------#
tn.write(command)
tn.read_until(")#",5)
## check MAC-address ##
tn.write("display mac-address port  %s \n" %port)
tn.write("\n \n")
out1=tn.read_until(")#",5)
nomac = "Failure:"
if nomac in out1:
    print ("There is no MAC address Found")
else:
    tn.write("display mac-address port  %s \n" %port)
    tn.write("\n \n")
    out1=tn.read_until("dl ",5)
    out2=tn.read_until("dynamic",10)
    print ("MAC-address is found : \n %s " %out2[2:16])
    ##check Stacking vlan##
    tn.write("display current-configuration section vlan-config | include vlan attrib 4\n")
    tn.read_until("\n vlan attrib ",5)
    out1=tn.read_until("stacking",5)
    out1 = out1[0:3]
    service = "inner-vlan"##
    ##check the configuration under port
    out = tn.write("display current-configuration section bbs-config | include %s v\n" %port)
    tn.read_until("service-port ",5)
    out=tn.read_until("outbound",5)
    #check if there is a configuration or not#
    if service not in out :
        print ("port not configured ")
        tn.close()
    else :
        print ("the configured Vlan is : %s " %out[9:13])
        print ("the  stacking Vlan is : %s " %out1)





No comments:

Post a Comment