Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
stop68673yMy proposal:
1. You can't access attributes of an class with indexes. there is an type called namedtuple that does this.
2. You need an loop to see if something matches your if clause
The best way for this that i know
@highlight
def x():
for i in arr:
if cmd in i:
Ping(i.ip_address)
break
else:
print("failed") -
you do know that literally every modern operating system (with gui) has a built-in screenshot feature?
-
Grumm17973y@tosensei senior IT manager here takes a photo of the screen (already awful because of 60Hz screens and high-end smartphone)
Send that picture with mail to his computer, then send it to whoever needs to see it. -
List Comprehension...
Generator...
Oh come on. That's homework... Do it at home by yourself. -
@IntrusionCM
Actually, it is not homework. I'm trying to create my own hacking simulator And it has been 10 years since I have done any programming.
I'm trying to design my code to where I can create npc computers and commands to be modular. So once it comes down to fleshing out the network and missions it is effortless. -
@MattSlaton
Despite my snarky remarks I gave you two hints. :)
You will need either a list or iterable to compare _multiple_ RemoteHost instances to a _single_ input. -
The solution I came up with was to append each of the classes inputs into a global variable. So far is seem to work.
Such as...
remote_ip = []
remote_machine = []
remote_user = []
remote_pass = []
root_pass = []
class RemoteHost():
def init(self, username, password, root_password, ip_address, machine):
remote_ip.append(ip_address)
remote_user.append(username)
remote_pass.append(password)
remote_machine.append(machine)
root_pass.append(root_password)
So each instance should append its own data to the appropriate lists. -
@MattSlaton Why not simply creating a list of RemoteHost objects?
Your approach defeats the purpose of an object... -
@IntrusionCM
One main reason I did it this way is because it doesn't break my existing code
It also allows me to keep the data for each host on the same index of each list.
But, I will take a look at doing that.
Could you provide an example of what you are talking about? -
Ok.i'm having weird sentimental issues.
class RemoteHost
def __init__(...)
self.username = username
...
Like in picture 1.
In Python, each object has public accessibility of variables.
You could define a global variable
KNOWN_HOSTS = [
RemoteHost(...),
RemoteHost(....)
]
So we have a list of objects.
What we need now is iterating over the list and finding a matching value.
Different approaches possible, though for sake of easiness, one possibility:
def search_known_hosts(keyword: str) -> Optional[RemoteHost]:
for remote_host in KNOWN_HOSTS:
if remote_host.username == ...
return remote_host
... (repeat for each class member)
return None
You can improve this step by step, but I think that should be the first naive solution to get your brain going. -
So, Make an object list then build a loop that will go through each instance of RemoteHost and check for a matching variable.
I think I get it. I'm going to go try it now. -
@IntrusionCM
Is there a way to have the Class instance append itself to the global variable?
This is what I have...
------------------------------------------------
remote_hosts = []
class RemoteHost():
def init(self, username, password, root_password, ip_address, machine):
self.username = username
self.password = password
self.root_password = root_password
self.ip_address = ip_address
self.machine = machine
remote_hosts.append(self)
google = RemoteHost("bob", "password", "toor", "10.10.10.10", "google-serv")
print(remote_hosts)
------------------------------------------------
OUTPUT
[<main.RemoteHost object at 0x7f8d5a08a4f0>]
------------------------------------------------
I expected it to print out the name of the class instance. Im not sure what to do from here. -
stop68673y@MattSlaton there are two methods related to printing. __str__(self) and __repr__(self)
the first one is printing out the object in an human manner. It can be anything you want/need, as long its an string.
The second is more technical. The default implementation prints out the module, classname and memory address, but like __str__can be anything, but its recommended to have it in the form of the initialisator with all arguments to replicate the object.
If no __str__ is defined __repr__ is used.
Related Rants
What would be the easiest way to make line 16 work.
I don't know if there is a simple way to tell this "if" argument to check all af the "Remote Host" classes for a matching string at that index.
I'm trying to design with modularity in mind.
question
python
coding