-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add examples/remoteshell.py as query usage example
- Loading branch information
Showing
2 changed files
with
32 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Sample to demonstrate usage of URI with query as a way | ||
# to send command remotely | ||
# | ||
# usage: | ||
# export TARGET_IP=192.168.1.5 | ||
# python remoteshell.py motd%3fmemset=p | ||
# | ||
|
||
#!/usr/bin/python3 | ||
import nbd | ||
import os | ||
import sys | ||
|
||
# TODO read from cli first [-h hostname] | ||
host = os.environ['TARGET_IP'] | ||
if not host: | ||
print("no host") | ||
|
||
n = len(sys.argv) | ||
if n > 1: | ||
query = sys.argv[1] | ||
|
||
# would need encoding URI | ||
|
||
h = nbd.NBD() | ||
uri = "nbd://" + host + '/' + query | ||
|
||
h.connect_uri(uri) | ||
ret = h.pread(512, 0) | ||
s = str(ret, 'utf-8') | ||
print(s) |
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