Skip to content

Commit

Permalink
Tools: update telnet_upload.py (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorxda authored Aug 13, 2023
1 parent 7c0489d commit 17b388a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ C library to work on vast majority of hardware.
**On a desktop computer:**
```
$ pip install Exscript
$ tools/telnet_upload.py 192.168.1.10
```
**On the shell:**
Expand Down
25 changes: 15 additions & 10 deletions tools/telnet_upload.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
#!/bin/python3

import os, sys, _thread, urllib.request
from Exscript.protocols import telnetlib
import os, sys, telnetlib, _thread, urllib.request

arm = "https://github.com/openipc/ipctool/releases/download/latest/ipctool"
mips = "https://github.com/openipc/ipctool/releases/download/latest/ipctool-mips32"

port = 23
name = "ipctool"
link = "https://github.com/openipc/ipctool/releases/download/latest/ipctool"

size = 200
path = "/tmp/ipctool"

def transfer():
t.write("rm -f " + path + "\n")
code = "rm -f " + path + "\n"
t.write(code.encode())
for index in range(0, len(file), size):
data = file[index : index + size]
text = data.hex("-").replace("-", "\\x")
t.write("echo -ne '\\x" + text.strip() + "' >> " + path + "\n")
t.write("chmod 755 " + path + "\n")
t.write(path + "\n")
text = "\\x".join(["{:02x}".format(x) for x in data])
code = "echo -ne '\\x" + text.strip() + "' >> " + path + "\n"
t.write(code.encode())
code = "chmod 755 " + path + "\n"
t.write(code.encode())
code = path + "\n"
t.write(code.encode())

def interact():
_thread.start_new_thread(t.listener, ())
Expand All @@ -26,7 +31,7 @@ def interact():
if line.strip() == "transfer":
transfer()
else:
t.write(line)
t.write(line.encode())

if len(sys.argv) < 2:
print("Usage:", sys.argv[0], "[host] [port]")
Expand All @@ -37,7 +42,7 @@ def interact():
port = sys.argv[2]

try:
urllib.request.urlretrieve(link, name)
urllib.request.urlretrieve(arm, name)
file = open(name, "rb").read()
except:
print("Cannot download or access", name)
Expand Down

0 comments on commit 17b388a

Please sign in to comment.