You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
1.1 KiB

7 years ago
  1. #!/usr/bin/python
  2. import subprocess
  3. import argparse
  4. import configparser
  5. import os
  6. HOME = os.path.expandvars('$HOME')
  7. cp = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
  8. cp.read('{HOME}/.ssh/config/hostnames.ini'.format(HOME=HOME))
  9. if __name__ == "__main__":
  10. parser = argparse.ArgumentParser()
  11. group = parser.add_mutually_exclusive_group(required=True)
  12. group.add_argument('-o','--wan',action = 'store_true')
  13. group.add_argument('-l','--lan',action = 'store_true')
  14. parser.add_argument('-p','--pre-script', help= 'script to run before connecting(in config dir)')
  15. parser.add_argument('name',help='name of config file to use (sans .cfg)')
  16. parser.add_argument('arg',nargs = '*')
  17. args = parser.parse_args()
  18. if args.pre_script:
  19. pre = '{HOME}/.ssh/config/{}'.format(args.pre_script,HOME=HOME)
  20. subprocess.check_call(pre)
  21. if args.wan:
  22. host = cp['wan'][args.name]
  23. elif args.lan:
  24. host = cp['lan'][args.name]
  25. cmd = ['ssh','-F','{HOME}/.ssh/config/{}.cfg'.format(args.name,HOME=HOME),host] + args.arg
  26. subprocess.call(cmd)