Check if credentials already exist for the given IP. Args: credentials_file: Path to the CSV file containing credentials ip: IP address to check Returns: List of (username, password) tuples, or None if no credentials
(credentials_file, ip)
| 21 | |
| 22 | @staticmethod |
| 23 | def check_existing_credentials(credentials_file, ip): |
| 24 | """ |
| 25 | Check if credentials already exist for the given IP. |
| 26 | |
| 27 | Args: |
| 28 | credentials_file: Path to the CSV file containing credentials |
| 29 | ip: IP address to check |
| 30 | |
| 31 | Returns: |
| 32 | List of (username, password) tuples, or None if no credentials exist |
| 33 | """ |
| 34 | if not os.path.exists(credentials_file): |
| 35 | return None |
| 36 | |
| 37 | credentials = [] |
| 38 | try: |
| 39 | with open(credentials_file, 'r') as f: |
| 40 | lines = f.readlines()[1:] # Skip header |
| 41 | for line in lines: |
| 42 | parts = line.strip().split(',') |
| 43 | if len(parts) >= 5 and parts[1] == ip: |
| 44 | credentials.append((parts[3], parts[4])) # (user, password) |
| 45 | except Exception as e: |
| 46 | logger.warning(f"Error reading existing credentials from {credentials_file}: {e}") |
| 47 | return None |
| 48 | |
| 49 | return credentials if credentials else None |
| 50 | |
| 51 | |
| 52 | class FileTracker: |