Skip to content

Commit

Permalink
add examples/remoteshell.py as query usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
bignaux committed Sep 24, 2023
1 parent ed0ac4b commit deb073c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions examples/remoteshell.py
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)
2 changes: 1 addition & 1 deletion plugins/memory/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static int memory_query(void *handle, struct query_param *params, int nb_params)
} else if (0 == strcmp(params[nb_params].key, "memset")) {
if (params[nb_params].val != NULL) {
LOG("val = %s\n", params[nb_params].val);
memset((char *)h->base, 75, h->size);
memset((char *)h->base, params[nb_params].val[0], h->size);
}
}
}
Expand Down

0 comments on commit deb073c

Please sign in to comment.