简体   繁体   English

使用Python反向IP查找

[英]Reverse IP Lookup with Python

How can I lookup all hosts hosted on an IP Address? 如何查找IP地址上托管的所有主机? I have checked Bing's API, but I don't think they provide free API key anymore to make a query with an IP Address. 我检查了Bing的API,但我认为他们不再提供免费的API密钥来使用IP地址进行查询。 Google probably would block after searching first 2-3 pages. 搜索前2-3页后Google可能会阻止。 I was also looking at the shodanhq api , but I think shodan doesnt support a reverse lookup! 我也在看shodanhq api ,但我认为shodan不支持反向查找!

I am using python 2.7 on Windows. 我在Windows上使用python 2.7。

May be this script is for you: 可能是这个脚本适合你:

import urllib2
import socket
import sys
import re

class reverseip(object):

            def __init__(self, server='http://www.ip-adress.com/reverse_ip/'):
                t= """ Tool made by: LeXeL lexelEZ[at]gmail[dot]com """
                print t

                try:
                    self.site = raw_input("Enter site to start scan: ")
                    self.fileout = raw_input("Enter logfile name: ")
                except KeyboardInterrupt:
                    print "\n\nError: Aborted"
                    sys.exit(1)

                self.server = server
                self.ua = "Mozilla/5.0 (compatible; Konqueror/3.5.8; Linux)"
                self.h = {"User-Agent": self.ua}

                self.write = True
                try:
                    outp = open(self.fileout, "w+")
                    outp.write(t)
                    outp.close()
                except IOError:
                    print '\n Failed to write to %s' % (self.fileout)
                    print '\n Continuing without writing'
                    self.write = False


            def url(self):
                r = urllib2.Request('%s%s' % (self.server, self.site), headers=self.h)
                f = urllib2.urlopen(r)
                self.source = f.read()
            def getip(self):
                try:
                    ip = socket.gethostbyname(self.site)
                except IOError, e:
                    print "Error: %s " %(e)
                else:      
                    print "\t\nScanning ip %s \n\n" %(ip)
            def whoami(self):
                found = re.findall("href=\"/whois/\S+\">Whois</a>]",self.source)
                for i in found:
                    i = i.replace("href=\"/whois/","")
                    i = i.replace("\">Whois</a>]","")
                    print "\t%s " % (i)
                    if self.write:
                        try:
                            outp = open(self.fileout, "a")
                            outp.write('%s\n' % (i))
                            outp.close()
                        except IOError:
                                print '\n Failed to write'
                                sys.exit(1)

if __name__ == '__main__':
    p = reverseip()
    p.url()
    p.getip()
    p.whoami()

With tiny modifciations you can get what you want....tell me what do you think, and let me know if I can help more...Thanks! 通过微小的修改你可以得到你想要的东西....告诉我你的想法,让我知道我是否可以帮助更多......谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM