Python反向IP查找

2024-10-01 15:33:31 发布

您现在位置:Python中文网/ 问答频道 /正文

如何查找IP地址上托管的所有主机?我已经检查了Bing的API,但我认为他们不再提供免费的API密钥来查询IP地址。谷歌可能会在搜索完前2-3个页面后屏蔽。我还查看了shodanhq api,但我认为shodan不支持反向查找!在

我在Windows上使用python2.7。在


Tags: apiwindows密钥页面屏蔽bingshodanshodanhq
1条回答
网友
1楼 · 发布于 2024-10-01 15:33:31

这个脚本可能是为您准备的:

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()

只要稍加修改,你就可以得到你想要的……告诉我你的想法,如果我能提供更多帮助,请告诉我……谢谢!在

相关问题 更多 >

    热门问题