http_banner获取v0.2-创新互联

#-*-coding=utf-8-*-
# __author__  = 'sanr'
# __email__   = '5754190@qq.com'
# __url__     = 'http://0x007.blog.51cto.com/'
# __version__ = '0.2'
import requests
import re
from threading import Thread,Lock
import time
import sys
import chardet
import netaddr
import struct
import socket

lock = Lock()

def ip2int(addr):
        return struct.unpack("!I", socket.inet_aton(addr))[0]
def int2ip(addr):
        return socket.inet_ntoa(struct.pack("!I", addr))
def int_dec(pagehtml):

        charset = None
        if pagehtml != '':
                # print 'use charset dect'
                enc = chardet.detect(pagehtml)
                # print 'enc= ', enc
                if enc['encoding'] and enc['confidence'] > 0.9:
                        charset = enc['encoding']

                if charset == None:
                        charset_re = re.compile("((^|;)\s*charset\s*=)([^\"']*)", re.M)
                        charset=charset_re.search(pagehtml[:1000]) 
                        charset=charset and charset.group(3) or None

                # test charset
                try:
                        if charset:
                                unicode('test',charset,errors='replace')
                except Exception,e:
                        print 'Exception',e
                        charset = None
        # print 'charset=', charset
        return charset


def http_banner(url):
        ip=url
        try:
                url=requests.get(url,timeout=2)        

                body = url.content
                
                charset = None
                if body != '':
                        charset = int_dec(body)

                if charset == None or charset == 'ascii':
                        charset = 'ISO-8859-1'

                if charset and charset != 'ascii' and charset != 'unicode':
                        try:
                                body = unicode(body,charset,errors='replace')
                        except Exception, e:
                                body = ''
                Struts=url.status_code
                Server=url.headers['server'][0:13]
                if Struts==200 or Struts==403 or Struts==401:
                        title=re.findall(r"(.*)<\/title>",body)
                        if len(title):
                                title = title[0].strip()
                        else:
                                title = ''
                        lock.acquire()
                        print ('%s\t%d\t%-10s\t%s'%(ip.lstrip('http://'),Struts,Server,title))
                        lock.release()
        except (requests.HTTPError,requests.RequestException,AttributeError,KeyError),e:
                pass



if __name__ == '__main__':
        if len(sys.argv) >= 2:
                ips = sys.argv[1]
        else:
                print 'usage: python http_banner.py 192.168.1./24 '
                print 'usage: python http_banner.py 192.168.1.1-192.168.1.254 '
                print 'usage: python http_banner.py 192.168.1./24 8080'
                print 'usage: python http_banner.py 192.168.1.1-192.168.1.254 8080'
                sys.exit()
        port = '80'
        if len(sys.argv) == 3:
                port = sys.argv[2]
                
        if '-' in ips:
                start, end = ips.split('-')
                startlong = ip2int(start)
                endlong = ip2int(end)
                ips = netaddr.IPRange(start,end)
                for ip in list(ips):
                        url='http://%s:%s'%(ip,port)
                        t = Thread(target=http_banner,args=(url,))
                        t.daemon=False
                        t.start()
        elif '/'        in ips:
                ips = netaddr.IPNetwork(ips)
                for ip in list(ips):
                        url='http://%s:%s'%(ip,port) 
                        t = Thread(target=http_banner,args=(url,))
                        t.daemon=False
                        t.start()</pre><p><strong>更新了端口自定义 默认端口为80</strong></p>创新互联于2013年创立,先为泰和等服务建站,泰和等地企业,进行企业商务咨询服务。为泰和企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。<p><strong><img src="/upload/otherpic16/131896.jpg" alt="http_banner获取v0.2"></strong></p><p><img src="/upload/otherpic16/131898.jpg" alt="http_banner获取v0.2"></p><p><img src="/upload/otherpic16/131902.jpg" alt="http_banner获取v0.2"></p><p align=center>另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、<a href="https://www.cdcxhl.com/gaofang/" target="_blank">高防服务器</a>、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。</p>            <br>
            本文标题:http_banner获取v0.2-创新互联            <br>
            新闻来源:<a href="http://bzwzjz.com/article/cdgsdp.html">http://bzwzjz.com/article/cdgsdp.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/ieocci.html">如何消除视频会议中出现的回音</a>
                </li><li>
                    <a href="/article/ieocsd.html">提高效率的Java代码小技巧有哪些</a>
                </li><li>
                    <a href="/article/ieocjo.html">CentOS7下安装配置proftpd搭建ftp服务器的详细教程</a>
                </li><li>
                    <a href="/article/ieocic.html">DataGrip有什么用</a>
                </li><li>
                    <a href="/article/ieocjj.html">如何使用py2exe将python脚本打包为exe</a>
                </li>        </ul>
    </div>
</div>
<div class="footer2">
    Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号 <br />友情链接:
    <a href="http://m.cdcxhl.cn/qiye/" target="_blank">企业网站建设 </a><a href="http://www.cxjianzhan.cn/fwxm/pinpai.html" target="_blank">成都品牌网站设计 </a><a href="http://www.cdweb.net/" target="_blank">自适应网站建设 </a><a href="http://www.cqcxhl.com/" target="_blank">网站设计 </a><a href="https://www.cdxwcx.com/" target="_blank">成都网站设计公司 </a><a href="http://www.cxjianzhan.com/" target="_blank">成都网站制作 </a><a href="http://m.cdcxhl.cn/dingzhi/" target="_blank">定制网站制作 </a><a href="https://www.cdxwcx.com/" target="_blank">做网站设计 </a><a href="http://www.cqcxhl.com/" target="_blank">重庆网站建设 </a><a href="http://www.bzwzjz.com/" target="_blank">成都网站设计制作公司 </a><a href="http://www.cxjianzhan.cn/" target="_blank">网站建设开发 </a><a href="http://www.kswcd.com/service/" target="_blank">上市集团网站建设 </a><a href="http://www.cxhljz.cn/" target="_blank">成都网站设计公司 </a><a href="http://m.cdcxhl.cn/mobile/" target="_blank">网站建设公司 </a><a href="http://www.bzwzjz.com/serve/" target="_blank">专业网站设计 </a><a href="http://www.cdweb.net/" target="_blank">成都网站建设 </a><a href="http://www.36103.cn/" target="_blank">成都网站设计 </a><a href="https://www.cdcxhl.com/shop.html" target="_blank">商城网站建设 </a><a href="http://www.cxjianzhan.com/" target="_blank">网站制作 </a><a href="http://www.cqcxhl.com/service/foreigntrade.html" target="_blank">重庆外贸网站建设 </a><a href="http://chengdu.cdcxhl.cn/seo/" target="_blank">营销网站建设 </a><a href="https://www.cdcxhl.com/yingxiao.html" target="_blank">成都营销网站建设 </a></div>

</body>
</html>
<script src="/Public/Home/js/wow.min.js"></script>
<script>
    if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))) {
        new WOW().init();
    };
</script>
<div class="sidebar">
    <ul>
        <li><a href="http://wpa.qq.com/msgrd?v=3&uin=244261566&site=www.bzwzjz.com&menu=yes" target="_blank"><img src="/Public/Home/images/right_qq.png" /></a></li>
        <li><a href="http://wpa.qq.com/msgrd?v=3&uin=1683211881&site=www.bzwzjz.com&menu=yes" target="_blank"><img src="/Public/Home/images/qq.png" /></a></li>
        <li class="tel"><a href="tel:028-86922220"><img src="/Public/Home/images/right_tel.png" /></a></li>
        <div class="wx">
            <span class="weixin"><img src="/Public/Home/images/weixin.jpg"><br> 微信扫一扫在线咨询</span>
        </div>
        <li><a class="fx" href="#hero"><img src="/Public/Home/images/right_up.png" /></a></li>
    </ul>
</div>
<script type="text/javascript">
    $(function () {
        $('.sidebar .fx').click(function () {
            $('html,body').animate({
                scrollTop: '0px'
            }, 800);
        });
    });
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#fancybox-manual-b").click(function () {
            $.fancybox.open({
                href: 'map.html',
                type: 'iframe',
                padding: 5
            });
        })
    });
</script>
<script>
    $(".con img").each(function(){
        var src = $(this).attr("src");    //获取图片地址
        var str=new RegExp("http");
        var result=str.test(src);
        if(result==false){
            var url = "https://www.cdcxhl.com"+src;    //绝对路径
            $(this).attr("src",url);
        }
    });
    window.onload=function(){
        document.oncontextmenu=function(){
            return false;
        }
    }
</script>