-
-
Save rtrouton/3cbfcc4000e55c5f7b1f71869b3be6b0 to your computer and use it in GitHub Desktop.
Script which creates a Python-hosted web server for TCP connection testing
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
#!/bin/bash | |
webdirectory=$(mktemp -d) | |
# Set port number for web service | |
port_number="8080" | |
# Create temporary directory and change directory | |
# into the temporary directory | |
cd "$webdirectory" | |
cat > "$webdirectory"/index.html << 'Index' | |
<html> | |
<head> | |
<title>Hello World</title> | |
</head> | |
<body> | |
Hello World | |
</body> | |
</html> | |
Index | |
# Run webservice | |
/usr/bin/python3 -m http.server "$port_number" |
The webdirectory variable would be useful only if... you would remove the folder at the end of the script or something, otherwise you can cd directly into the temp folder like:
cd $(mktemp -d)
And the port number could be optional like an argument ($1?). Without any argument it would try to bind on 8000/tcp.
But I would still use for a simple task like this netcat instead.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ofc you can pass the "content" many ways like heredoc, from a file, etc...