예제 #1
0
    def __init__(self, domain):
        if domain[:4] == "http":
            print("不能包含http和https字样,如果有端口要加上端口")
            return
        headers = {
            'Connection':
            'close',
            'User-Agent':
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.9 Safari/537.36'
            #这里一定要设置UA,否则会出现错误
        }

        if ':' in domain:
            searchobj = re.search('(.*):(.*)$', domain)
            self.port = searchobj.group(2)
            self.domain = searchobj.group(1)
            #self.http_or_https=get_http_or_https(self.domain)
            if self.port == '80':
                self.http_or_https = 'http'
            elif self.port == '443':
                self.http_or_https = 'https'
            else:
                self.http_or_https = get_http_or_https(self.domain)
        else:
            self.domain = domain
            self.http_or_https = get_http_or_https(self.domain)

            if self.http_or_https == 'http':
                self.port = '80'
            else:
                self.port = '443'

        #print('domain使用的协议是:%s' % self.http_or_https)
        rep_test = requests.get(self.http_or_https + "://" + self.domain +
                                ":" + self.port,
                                timeout=10,
                                verify=False,
                                headers=headers).text

        soup = BeautifulSoup(rep_test, 'lxml')
        self.domain_title = soup.title.string
        print('domain使用的协议是:%s, %s' % (self.http_or_https, self.domain_title))
        #print('domain使用的协议是:%s' % self.http_or_https)
        #result=get_request(self.http_or_https+"://"+self.domain,'seleniumPhantomJS')
        #self.domain_title=result['title']
        #下面调用相当于main函数的get_actual_ip_from_domain函数
        #self.get_ip_value_from_ip138()
        #self.get_ip_value_from_fofa()
        #'''
        actual_ip = self.get_actual_ip_from_domain()
        if actual_ip != 0:
            print("恭喜, %s 的真实ip是 %s" % (self.domain, actual_ip))
        #下面用来存放关键返回值
        self.return_value = actual_ip
예제 #2
0
파일: xcdn.py 프로젝트: 3xp10it/xcdn
    def __init__(self, domain):
        #必须保证连上了vpn,要在可以ping通google的条件下使用本工具,否则有些domain由于被GFW拦截无法正常访问会导致
        #本工具判断错误,checkvpn在可以ping通google的条件下返回1
        while 1:
            if checkvpn() == 1:
                break
            else:
                time.sleep(1)
                print("vpn is off,connect vpn first")
        if domain[:4] == "http":
            print(
                "domain format error,make sure domain has no http,like www.baidu.com but not \
http://www.baidu.com")
            sys.exit(0)
        #首先保证hosts文件中没有与domain相关的项,有则删除相关
        domainPattern = domain.replace(".", "\.")
        #下面的sed的正则中不能有\n,sed匹配\n比较特殊
        #http://stackoverflow.com/questions/1251999/how-can-i-replace-a-newline-n-using-sed
        command = "sudo sed -ri 's/.*\s+%s//' /etc/hosts" % domainPattern
        os.system(command)

        self.domain = domain
        self.http_or_https = get_http_or_https(self.domain)
        print('domain的http或https是:%s' % self.http_or_https)
        result = get_request(self.http_or_https + "://" + self.domain,
                             'seleniumPhantomJS')
        self.domain_title = result['title']
        #下面调用相当于main函数的get_actual_ip_from_domain函数
        actual_ip = self.get_actual_ip_from_domain()
        if actual_ip != 0:
            print("恭喜,%s的真实ip是%s" % (self.domain, actual_ip))
        #下面用来存放关键返回值
        self.return_value = actual_ip