Skip to content

Instantly share code, notes, and snippets.

@guerbai
Created January 30, 2017 15:24
Show Gist options
  • Save guerbai/3247ac1f433aa3e869294761f9eda046 to your computer and use it in GitHub Desktop.
Save guerbai/3247ac1f433aa3e869294761f9eda046 to your computer and use it in GitHub Desktop.
Python获得调用系统命令在命令行的输出.
import commands
def get_location(ip):
cmd = "curl http://www.ip.cn/{}".format(ip)
result = commands.getoutput(cmd)
location = result.split("\n")[-1].split(":")[-1]
return location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment