Last active
November 13, 2019 12:24
-
-
Save benwei/f6d869f7587a3bb4db1e4d8ea4322c98 to your computer and use it in GitHub Desktop.
python script convert string to hex as echo -e command, tested with python 2.7 and 3.5
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
~$ python2.7 str_to_hex_for_echo_cmd.py | |
echo -e "testecho_\x21#\x24%\x2a\x5c'\x5c\x22\x21~?<>\x3a| 89920." | |
~$ python3.5 str_to_hex_for_echo_cmd.py | |
echo -e "testecho_\x21#\x24%\x2a\x5c'\x5c\x22\x21~?<>\x3a| 89920." | |
~$ echo -e "testecho_\x21#\x24%\x2a\x5c'\x5c\x22\x21~?<>\x3a| 89920." | |
testecho_!#$%*\'\"!~?<>:| 89920. |
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
sample="""testecho_!#$%*\\'\\"!~?<>:| 89920.""" | |
echo_validates = "#% _~'?><|,." | |
data = [] | |
for c in sample: | |
if c.isalpha() or c.isdigit() or c in echo_validates: | |
data.append(c) | |
else: | |
data.append("\\x%0x" % ord(c)) | |
print('echo -e "%s"\n' % "".join(data)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment