Guest User

Untitled

a guest
Dec 24th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. import argparse
  2. import sys, getpass
  3.  
  4. parser = argparse.ArgumentParser()
  5. parser.add_argument('connect', help = '[username@host], [host]')
  6. parser.add_argument('-E', help = '-E logfile')
  7. parser.add_argument('-p', type = int, help = '-p port')
  8. parser.add_argument('-l', help = '-l login_name')
  9. parser.add_argument('-L', help = '-L adress')
  10. parser.add_argument('-W', help = '-W host:port')
  11. parser.add_argument('--connection', help = 'connect', action = 'store_true')
  12. parser.add_argument('--noconnection', help = 'noconnect', action = 'store_true')
  13.  
  14. if len(sys.argv) == 1:
  15. print('---------------------------------------------------------------\n')
  16. parser.print_help()
  17. print('\n---------------------------------------------------------------')
  18. sys.exit(0)
  19.  
  20. args = parser.parse_args()
  21.  
  22. password = host = password = ""
  23. port = 22
  24.  
  25. if args.connection and args.noconnection:
  26. print('---------------------------------------------------------------\n')
  27. print('Use only one, --connection or --noconnection')
  28. parser.print_help()
  29. print('\n---------------------------------------------------------------')
  30. sys.exit(0)
  31.  
  32.  
  33. if args.p:
  34. port = args.p
  35.  
  36. if args.connect:
  37. if '@' in args.connect:
  38. username = args.connect.split('@')[0]
  39. host = args.connect.split('@')[1]
  40. password = getpass.getpass('Password: ')
  41. else:
  42. if not args.L and not args.W:
  43. host = args.connect
  44. username = (input('Username: '))
  45. password = getpass.getpass('Password: ')
  46.  
  47. if args.l:
  48. username = args.l
  49.  
  50. if args.L:
  51. host = args.L
  52.  
  53. if args.W:
  54. if ':' in args.W:
  55. host = args.W.split(':')[0]
  56. port = int(args.W.split(':')[1])
  57.  
  58.  
  59. if not args.E:
  60. if password == 'raspberry' and username == 'pi' and host == 'localhost' and port == 22:
  61. print('Connecting to %s on port %d with username %s...' % (host, port, username))
  62. print('Connection successful!\n\n')
  63. else:
  64. print('Error connecting to %s on port %d with user %s: Unknown user' % (host, port, username))
  65. else:
  66. if args.connect:
  67. f = open(args.E, 'w')
  68. if password == 'raspberry' and username == 'pi' and host == 'localhost' and port == 22:
  69. f.write('Connecting to %s with username %s...\n' % (host, username))
  70. f.write('Connection successful!\n\n\n')
  71. else:
  72. f.write('Error connecting to %s with user %s: Unknown user\n' % (host, username))
  73. f.close()
Add Comment
Please, Sign In to add comment