Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###############################################################
- #
- # Synaccess Networks, Inc. (www.synaccess-net.com)
- # Jan. 6th, 2013
- # Python Script Example 1
- # for NP series.
- # https://www.synaccess-net.com/support/
- # https://www.synaccess-net.com/s/np_rb.py
- ################################################################
- import socket
- import time
- import sys
- import datetime
- def connect(ip_value, port_value):
- HOST = str(ip_value)
- PORT = int(port_value)
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect((HOST, PORT))
- #print('{:%m/%d/%Y}'.format(datetime.datetime.now()))
- #print('{:%H:%M:%S}'.format(datetime.datetime.now()))
- time.sleep(0.1) #use time.sleep to give delay and netBooter time to process
- sock.send('\r') #send \r to start at beginning of line
- time.sleep(0.5)
- sock.send('login\r')
- time.sleep(0.5)
- sock.send('admin\r') # username
- time.sleep(0.5)
- sock.send('admin\r') # password
- time.sleep(0.5)
- sock.send('setup\r')
- time.sleep(0.5)
- sock.send('2\r')
- time.sleep(1.0)
- sock.send('2\r')
- time.sleep(1.0)
- sock.send('{:%m/%d/%Y}\r'.format(datetime.datetime.now()))
- time.sleep(2.0)
- sock.send('3\r')
- time.sleep(2.0)
- sock.send('{:%H:%M:%S}\r'.format(datetime.datetime.now()))
- time.sleep(2.0)
- sock.send('s\r')
- time.sleep(0.5)
- sock.send('q\r')
- time.sleep(0.5)
- sock.send('s\r')
- time.sleep(0.5)
- sock.send('q\r')
- time.sleep(0.5)
- sock.send('logout\r')
- #recv = sock.recv(8192) #receive data from session
- #print(recv) #print data received
- time.sleep(0.1)
- sock.close()
- def main():
- if len(sys.argv) !=5:
- print('\r\n')
- print('Example:> np_term.py -i 192.168.1.100 -p 23\r\n')
- print(' np_term.py -i Unit_IP_Addr -p Telnet_port# \r\n')
- sys.exit(1)
- ip = sys.argv[1] #For -i option in command line
- ip_value = sys.argv[2] #IP address value entered
- port = sys.argv[3] #For -p option in command line
- port_value = sys.argv[4] #Port number entered
- if ip == '-i' and port == '-p': #Check that the command line uses both -i and -p for valid connection
- connect(ip_value,port_value)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement