-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from zTrix/new_zio
New zio version 2.0
- Loading branch information
Showing
27 changed files
with
2,386 additions
and
1,697 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
dist | ||
build | ||
zio.egg-info | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,41 @@ | ||
language: python | ||
python: | ||
- "2.6" | ||
- "2.7" | ||
install: | ||
- "sudo apt-get install --no-install-recommends socat" | ||
- "pip install termcolor" | ||
script: | ||
- python test/test.py | ||
|
||
jobs: | ||
include: | ||
- language: python | ||
python: "3.8" | ||
before_install: | ||
- "sudo apt-get install -y --no-install-recommends socat" | ||
script: | ||
- ./test3/test.sh | ||
- language: python | ||
python: "3.7" | ||
before_install: | ||
- "sudo apt-get install -y --no-install-recommends socat" | ||
script: | ||
- ./test3/test.sh | ||
- language: python | ||
python: "3.6" | ||
before_install: | ||
- "sudo apt-get install -y --no-install-recommends socat" | ||
script: | ||
- ./test3/test.sh | ||
- language: python | ||
python: "3.5" | ||
before_install: | ||
- "sudo apt-get install -y --no-install-recommends socat" | ||
script: | ||
- ./test3/test.sh | ||
- language: python | ||
python: "2.7" | ||
before_install: | ||
- "sudo apt-get install -y --no-install-recommends socat" | ||
script: | ||
- ./test2/test.sh | ||
- language: python | ||
dist: trusty | ||
python: "2.6" | ||
before_install: | ||
- "sudo apt-get install -y --no-install-recommends socat" | ||
script: | ||
- ./test2/test.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
from zio import * | ||
|
||
io = zio(('github.com', 80), print_read=COLORED(HEXDUMP, 'yellow'), print_write=COLORED(HEXDUMP_INDENT8, 'cyan')) | ||
io.write(b'GET / HTTP/1.0\r\n\r\n') | ||
io.read() | ||
|
||
io.close() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env python | ||
|
||
# a minimal version socket-only zio which guaranteed to work for python2/3 on Linux/Mac and even for windows | ||
from telnetlib import Telnet | ||
import socket | ||
|
||
class zio: | ||
def __init__(self, target): | ||
self.io = socket.create_connection(target) | ||
|
||
def read_until(self, pattern): | ||
if not pattern: | ||
return b'' | ||
data = b'' | ||
while True: | ||
c = self.io.recv(1) | ||
if not c: | ||
raise ValueError('pattern not found, buffer = %s' % data) | ||
|
||
data += c | ||
if pattern in data: | ||
return data | ||
|
||
readuntil = read_until | ||
|
||
def read(self, n=None): | ||
is_read_all = n == -1 or n is None | ||
data = b'' | ||
while True: | ||
num = 1024 if is_read_all else n-len(data) | ||
c = self.io.recv(num) | ||
if not c: | ||
break | ||
data += c | ||
if len(data) == n: | ||
break | ||
return data | ||
|
||
def read_line(self): | ||
return self.read_until(b'\n') | ||
|
||
readline = read_line | ||
|
||
def write(self, data): | ||
self.io.sendall(data) | ||
|
||
def write_line(self, data): | ||
self.io.sendall(data + b'\n') | ||
|
||
writeline = write_line | ||
|
||
def interact(self): | ||
t = Telnet() | ||
t.sock = self.io | ||
t.interact() | ||
|
||
def close(self): | ||
self.io.close() | ||
|
||
if __name__ == '__main__': | ||
print(''' | ||
# This is a minimal version socket-only io which guaranteed to work for python2/3 on Linux/Mac and even for windows | ||
# example usage | ||
from mini_zio import * | ||
io = zio(('target', 1234)) | ||
banner = io.read_line() | ||
io.read_until(b'username:') | ||
io.write_line(b'admin') | ||
io.interact() | ||
io.close() | ||
''') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
set -ex | ||
|
||
CWD=$(cd "${0%/*}" && pwd) | ||
|
||
docker=podman | ||
|
||
$docker run -it --rm -v $CWD:/data/ python:2.6 /data/test2/test.sh | ||
$docker run -it --rm -v $CWD:/data/ python:2.7 /data/test2/test.sh | ||
$docker run -it --rm -v $CWD:/data/ python:3.5 /data/test3/test.sh | ||
$docker run -it --rm -v $CWD:/data/ python:3.7 /data/test3/test.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
./test3/test.sh | ||
./test2/test.sh |
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.