₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,329,266 members, 8,439,631 topics. Date: Sunday, 05 July 2026 at 05:18 PM

Toggle theme

Please Someone Should Read This Code... - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPlease Someone Should Read This Code... (585 Views)

1 Reply (Go Down)

Please Someone Should Read This Code... by Nick08130(op): 6:47am On Nov 04, 2022
```python
#!/usr/bin/env python3

# Python SSH Checker
# Fix indent =G:wq
import argparse
import socket
import paramiko
import sys
import os

class SystemScanner:

def __init__(self, target, port, service):
#Globals?
self.target = target
self.port = port
self.service = service

def test_ssh(self):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect((self.target, self.port))
print("SSH Open"wink
except Exception as err:
#Conn failed
print(f"Connection failed on "wink
finally:
sock.close()

def ssh_auth(self):
test = paramiko.Transport((self.target, self.port))
try:
test.connect()
except paramiko.ssh_exception.SSHException as err:
print(f"SSH Connection failed:", self.host, self.port, "because ", str(err))
test.close()
exit(1)
try:
test.auth_none('')
except paramiko.BadAuthenticationType as err:
print(err.allowed_types)
finally:
test.close()

def ssh_login(self):
print(f"Checking {self.service} logins..."wink
try:
print("Dropping into shell"wink
command = "journalctl --system --follow | grep -i ssh"
'''TODO
1) Parse output and find get the info cleaner
2) Add Services [http, ftp, smb]
3) clean exit
4) Counters for successfull/failed logins
'''

os.system(command)
except KeyboardInterrupt as kd:
exit(1)
finally:
print("\n\n\r\nEND"wink


if __name__ == '__main__':
parser = argparse.ArgumentParser(prog="sysmon.py"wink
parser.add_argument('--port', '-p', help="Enter Port Number", type=int, default=22)
parser.add_argument('--target', '-t', help='Hostname or IP', default="127.0.0.1"wink
parser.add_argument('--service', '-s', help="Show Service logins", default="ssh"wink
args = parser.parse_args()

scanner = SystemScanner(args.target, args.port, args.service)
if scanner.test_ssh():
scanner.ssh_auth()
if args.service:
scanner.ssh_login()
```
Re: Please Someone Should Read This Code... by bedfordng(m): 11:38am On Nov 04, 2022
The code is self explanatory. Code is simply used for making SSH connection. So when running the script you have to add the arguments such as target, port , service etc along with the script else it won't work.

Are you the one that created it.
Re: Please Someone Should Read This Code... by Skodrran(m): 3:11pm On Nov 04, 2022
Socket programming undecided
1 Reply

I Am Bored, I Just Tried This CodeEyeopener: Aspiring Nigerian Game/App Developers Should Read ThisPlease,Help Explain This Code In C234

Why Are Nigerians Accepting Low Pay In Tech?Happy New Year Software DeveloperFree Web Design And Development Training