Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess
- class Interpreter(object):
- def __init__(self, text):
- self.text = text
- self.tokens = []
- def error(self):
- raise Exception('Error parsing input')
- def expr(self):
- self.tokens = self.text.split(" ")
- #return self.tokens
- if self.tokens[0] == "show":
- if self.tokens[1] == "ip" and self.tokens[2] == "route":
- f = open('/proc/net/route', 'r')
- result = f.read()
- return result
- if self.tokens[1] == "interfaces":
- result = subprocess.call(["ifconfig"])
- return result
- if self.tokens[1] == "interface":
- result = subprocess.call(["ifconfig", self.tokens[2]])
- return result
- return self.error
- def main():
- while True:
- try:
- text = raw_input('cisco> ')
- except EOFError:
- break
- if not text:
- continue
- interpreter = Interpreter(text)
- result = interpreter.expr()
- print(result)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement