Skip to content

Commit

Permalink
# v1.0.2 一些小细节完善
Browse files Browse the repository at this point in the history
  • Loading branch information
Toyo committed Mar 11, 2017
1 parent b63f535 commit d973dd1
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions pythonhttp.sh
Expand Up @@ -3,10 +3,11 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

#=================================================
# System Required: All
# Description: Python HTTP Server
# Author: Toyo
# Blog: https://doub.io/wlzy-8/
# System Required: All
# Description: Python HTTP Server
# Version: 1.0.2
# Author: Toyo
# Blog: https://doub.io/wlzy-8/
#=================================================

sethttp(){
Expand All @@ -15,10 +16,10 @@ sethttp(){
do
echo -e "请输入要开放的HTTP服务端口 [1-65535]"
stty erase '^H' && read -p "(默认端口: 8000):" httpport
[ -z "$httpport" ] && httpport="8000"
[[ -z "$httpport" ]] && httpport="8000"
expr ${httpport} + 0 &>/dev/null
if [ $? -eq 0 ]; then
if [ ${httpport} -ge 1 ] && [ ${httpport} -le 65535 ]; then
if [[ $? -eq 0 ]]; then
if [[ ${httpport} -ge 1 ]] && [[ ${httpport} -le 65535 ]]; then
echo
echo -e " 端口 : \033[41;37m ${httpport} \033[0m"
echo
Expand All @@ -33,8 +34,8 @@ sethttp(){
#设置目录
echo "请输入要开放的目录(绝对路径)"
stty erase '^H' && read -p "(直接回车, 默认当前文件夹):" httpfile
if [ ! -z $httpfile ]; then
[ ! -e $httpfile ] && echo -e "\033[41;37m [错误] \033[0m 输入的目录不存在 或 当前用户无权限访问, 请检查!" && exit 1
if [[ ! -z $httpfile ]]; then
[[ ! -e $httpfile ]] && echo -e "\033[41;37m [错误] \033[0m 输入的目录不存在 或 当前用户无权限访问, 请检查!" && exit 1
else
httpfile=`echo $PWD`
fi
Expand All @@ -59,18 +60,18 @@ iptables_del(){
}
starthttp(){
PID=`ps -ef | grep SimpleHTTPServer | grep -v grep | awk '{print $2}'`
[ ! -z $PID ] && echo -e "\033[41;37m [错误] \033[0m SimpleHTTPServer 正着运行,请检查 !" && exit 1
[[ ! -z $PID ]] && echo -e "\033[41;37m [错误] \033[0m SimpleHTTPServer 正着运行,请检查 !" && exit 1
sethttp
iptables_add
cd ${httpfile}
nohup python -m SimpleHTTPServer $httpport >> httpserver.log 2>&1 &
sleep 2s
PID=`ps -ef | grep SimpleHTTPServer | grep -v grep | awk '{print $2}'`
if [ -z $PID ]; then
if [[ -z $PID ]]; then
echo -e "\033[41;37m [错误] \033[0m SimpleHTTPServer 启动失败 !" && exit 1
else
ip=`curl -m 10 -s http://members.3322.org/dyndns/getip`
[ -z "$ip" ] && ip="VPS_IP"
[[ -z "$ip" ]] && ip="VPS_IP"
echo
echo "HTTP服务 已启动 !"
echo -e "浏览器访问,地址: \033[41;37m http://${ip}:${httpport} \033[0m "
Expand All @@ -79,13 +80,13 @@ starthttp(){
}
stophttp(){
PID=`ps -ef | grep SimpleHTTPServer | grep -v grep | awk '{print $2}'`
[ -z $PID ] && echo -e "\033[41;37m [错误] \033[0m 没有发现 SimpleHTTPServer 进程运行,请检查 !" && exit 1
[[ -z $PID ]] && echo -e "\033[41;37m [错误] \033[0m 没有发现 SimpleHTTPServer 进程运行,请检查 !" && exit 1
port=`netstat -lntp | grep ${PID} | awk '{print $4}' | awk -F ":" '{print $2}'`
iptables_del
kill -9 ${PID}
sleep 2s
PID=`ps -ef | grep SimpleHTTPServer | grep -v grep | awk '{print $2}'`
if [ ! -z $PID ]; then
if [[ ! -z $PID ]]; then
echo -e "\033[41;37m [错误] \033[0m SimpleHTTPServer 停止失败 !" && exit 1
else
echo
Expand All @@ -95,7 +96,7 @@ stophttp(){
}

action=$1
[ -z $1 ] && action=start
[[ -z $1 ]] && action=start
case "$action" in
start|stop)
${action}http
Expand Down

0 comments on commit d973dd1

Please sign in to comment.