根据IP查询地址

上一篇 / 下一篇  2008-07-25 11:11:38 / 个人分类:开发语言Python

输入IP地址,网上获取数据后显示

# -*- coding: mbcs -*-
import sys
import urllib2;

helpText="""
    python getAddress.py <filename> <ip>
"""

def help():
    print helpText

def getAddress(ip):
    if len(ip)>6:
        URL='http://www.ip.cn/?q='+ip.strip()
        tempFile = urllib2.urlopen(URL).read().decode('utf-8')
        a = tempFile.index('查询结果为:'.decode('mbcs'))
        b = tempFile[a:].index('\n'.decode('mbcs'))
        return tempFile[a+6:a+b-1]

if __name__ == "__main__":
    if len(sys.argv) < 2:
        help()
        sys.exit()
    for arg in sys.argv[1:]:
        print getAddress(arg)


TAG: python IP 开发语言Python

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-19  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 5630
  • 日志数: 3
  • 建立时间: 2007-11-12
  • 更新时间: 2008-07-25

RSS订阅

Open Toolbar