Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[closed] invalid branch #2

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
30 changes: 16 additions & 14 deletions mikrotikapi-bf.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,21 @@ def open_socket(self):
self.sock = socket.socket(af, socket.SOCK_STREAM)
self.sock.settimeout(5) # Set socket timeout to 5 seconds, default is None

try:
# Trying to connect to RouterOS, error can occur if IP target is not reachable, or API is blocked in
# RouterOS firewall or ip services, or port is wrong.
self.connection = self.sock.connect(sa)

except (socket.timeout):
print("[-] SOCKET TIMEOUT! Target timed out! Exiting...")
self.close()
sys.exit(1)

except OSError:
print("[-] SOCKET ERROR! Check Target (IP or PORT parameters). Exiting...")
raise CreateSocketError('Error: API failed to connect to socket. Host: {}, port: {}.'.format(self.target, self.port))
connected = False
while not connected:
try:
# Trying to connect to RouterOS, error can occur if IP target is not reachable, or API is blocked in
# RouterOS firewall or ip services, or port is wrong.
self.connection = self.sock.connect(sa)
connected = True

except (socket.timeout):
print("[-] SOCKET TIMEOUT! Target timed out!")
time.sleep(60)

except OSError:
print("[-] SOCKET ERROR! Check Target (IP or PORT parameters). Exiting...")
raise CreateSocketError('Error: API failed to connect to socket. Host: {}, port: {}.'.format(self.target, self.port))

# if self.use_ssl:
# try:
Expand Down Expand Up @@ -262,7 +264,7 @@ def read_sentence():
# Everything will be appended to paragraph variable, and then returned.
paragraph = []
received_sentence = ['']
while received_sentence[0] != '!done':
while received_sentence and received_sentence[0] != '!done':
received_sentence = read_sentence()
paragraph.append(received_sentence)
self.status = paragraph
Expand Down