0

I have made a script which is used to run an APP on MACOS It basically controls camera using and IP address

My problem is it required a password

I am using the http://docs.python.org/2/library/telnetlib.html#telnetlib.Telnet example from here but it is not working I do not want it to prompt the user for the password, I simply want to HardCode it everytime the app runs.

if ip:
        self.conn = telnetlib.Telnet(ip, 24)
        self.consume_telnet()
    else:
        self.conn = None


def telnet_send(self, s):
    passCode = '********'                            
    password = getpass.getpass()
    if self.conn:
        self.conn.write(s + '\r\n')
        if password:
            self.conn.read_until('Password: ')
            self.conn.write(password.strip() + '\n')

    else:
        print s
user3337714
  • 663
  • 1
  • 7
  • 25

1 Answers1

0

Password is prompted by getpass.getpass() call. This method always asks user for the password. Check this doc page: http://docs.python.org/2/library/getpass.html

I am assuming you are doing initialization outside telnet_send method. Simply setup your password inside this initialization code --- something like self.password = getpass.getpass() and then use this password elsewhere.

self.password = getpass.getpass()

def telnet_send(self, s):
   passCode = '********'                            
   if self.conn:
      self.conn.write(s + '\r\n')
      if self.password:
          self.conn.read_until('Password: ')
          self.conn.write(self.password.strip() + '\n')
   else:
       print s
Sudeep Juvekar
  • 4,898
  • 3
  • 29
  • 35
  • Thanks for the reply. It still prompts me for the password. I don't want it to prompt me for the password at all. I tried your code but in vain. I simply want to HARDCODE the password, no user input is ever needed!! – user3337714 Feb 21 '14 at 16:25
  • Do you expect to run a script that automatically extracts a user's unix password? That'd be bad for a user, right? If a user consents to enter a password at a prompt, that's fine - it's his/her responsibility. But a 3rd party passcode harvesting script is plain bad. You can get a password hash etc. Try http://docs.python.org/2/library/hashlib.html – Sudeep Juvekar Feb 21 '14 at 16:41
  • This has nothing to do with anything problematic The above code is a part of my Class module It calls an IP address. The IP address is for Video-Conferencing CAMERA. The code is to help the Video-Admin to change Camera Position. It open a GUI Dialog box with Camera Position. You can click on any camera: Now at the time of click the password is needed once to accept all changes. So I want to HardCode the password for the Video admin. The GUI cannot prompt a password, therefore HardCODE is the only choice. The above code is somehow not able to implement the same. – user3337714 Feb 21 '14 at 16:57