python小技巧

命令行启动简单的httpserver:

python3:

$ python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
10.1.21.242 - - [27/Sep/2017 18:24:34] "GET / HTTP/1.1" 200 -
10.1.21.242 - - [27/Sep/2017 18:24:34] code 404, message File not found
10.1.21.242 - - [27/Sep/2017 18:24:34] "GET /favicon.ico HTTP/1.1" 404 -
10.1.21.242 - - [27/Sep/2017 18:24:37] "GET /%E5%85%AC%E5%8F%B8%E5%8A%9E%E5%85%AC%E7%BD%91%E7%BF%BB%E5%A2%99%E9%85%8D%E7%BD%AE%E6%96%B9%E6%B3%95.docx HTTP/1.1" 200 -
10.10.2.242 - - [27/Sep/2017 18:27:11] "GET / HTTP/1.1" 200 -

 

python2:

$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
10.1.21.242 - - [27/Sep/2017 18:31:46] "GET / HTTP/1.1" 200 -
10.1.21.242 - - [27/Sep/2017 18:31:47] "GET / HTTP/1.1" 200 -

 

 

格式化输出:

$ echo '{"a":1, "b":2}' | python -m json.tool
{
      "a": 1,
      "b": 2
}

 

用python快速实现ftp:
# pip install pyftpdlib

# python3 -m pyftpdlib
[I 2018-01-30 11:15:15] >>> starting FTP server on 0.0.0.0:2121, pid=31872 <<<
[I 2018-01-30 11:15:15] concurrency model: async
[I 2018-01-30 11:15:15] masquerade (NAT) address: None
[I 2018-01-30 11:15:15] passive ports: None


$ ftp 10.10.88.31 2121
Connected to 10.10.88.31.
220 pyftpdlib 1.5.3 ready.
Name (10.10.88.31:rr): anonymous
331 Username ok, send password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

 

# python3 -m pyftpdlib -h
Usage: python -m pyftpdlib [options]

Start a stand alone anonymous FTP server.

Options:
-h, --help
show this help message and exit

-i ADDRESS, --interface=ADDRESS
specify the interface to run on (default all interfaces)

-p PORT, --port=PORT
specify port number to run on (default 2121)

-w, --write
grants write access for logged in user (default read-only)

-d FOLDER, --directory=FOLDER
specify the directory to share (default current directory)

-n ADDRESS, --nat-address=ADDRESS
the NAT address to use for passive connections

-r FROM-TO, --range=FROM-TO
the range of TCP ports to use for passive connections (e.g. -r 8000-9000)

-D, --debug
enable DEBUG logging evel

-v, --version
print pyftpdlib version and exit

-V, --verbose
activate a more verbose logging

-u USERNAME, --username=USERNAME
specify username to login with (anonymous login will be disabled and password required if supplied)

-P PASSWORD, --password=PASSWORD
specify a password to login with (username required to be useful)

 

 

快速验证模块是否已经安装:

# python -c "import paramiko"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named paramiko


# python3 -c "import paramiko"

 

posted @ 2017-09-27 18:40  helloworld899  阅读(160)  评论(0编辑  收藏  举报