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://dcwzsj.com/article/cdgsdp.html">http://dcwzsj.com/article/cdgsdp.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/gpgdec.html">API网关有哪些优缺点</a>
                </li><li>
                    <a href="/article/gpgdjc.html">eclipse构建自定义菜单的实现</a>
                </li><li>
                    <a href="/article/gpgdid.html">如何解决linuxftp匿名上传、下载开机自启问题</a>
                </li><li>
                    <a href="/article/gpgogj.html">css中行级元素和块级元素之间转换的方法</a>
                </li><li>
                    <a href="/article/gpgdpo.html">DNS服务</a>
                </li>        </ul>
    </div>
</div>
<div class="footer">
    <div class="contain">
        <div class="foot-nav clearfix">
            <ul class="footer-menu">
                <li class="dropdown" ><a class="dropdown-toggle">服务范围<b class="caret"></b></a>
                    <ul class="child-menu">
                        <li><a href="/website.html">网站建设</a></li>
                        <li><a href="/weixin/" rel="nofollow">微信开发</a></li>
                        <li><a href="/app/" rel="nofollow">APP开发</a></li>
                        <li><a href="/design/" rel="nofollow">品牌设计</a></li>
                        <li><a href="/market/" rel="nofollow">营销推广</a></li>
                    </ul>
                </li>
                <li class="dropdown"><a href="/webcase/" class="dropdown-toggle" title=德昌县做网站案例>德昌县做网站案例<b class="caret"></b></a>
                    <ul class="child-menu">
                        <li><a href="/webcase/jtssgslist.html" id="ctl00_show_85" title="集团上市公司">集团上市公司</a></li>
                        <li><a href="/webcase/ppwzlist.html" id="ctl01_show_81" title="品牌网站">品牌网站</a></li>
                        <li><a href="/webcase/xiangyingshilist.html" id="ctl02_show_82" title="响应式网站">响应式网站</a></li>
                        <li><a href="/Marketingwebsite/index.html" id="ctl03_show_83" title="营销型网站">营销型网站</a></li>
                        <li><a href="/waimaowangzhan/index.html" id="ctl04_show_84" title="外贸网站">外贸网站</a></li>
                    </ul>
                </li>
                <li class="dropdown"><a href="/news/" class="dropdown-toggle">新闻中心 <b class="caret"></b></a>
                    <ul class="child-menu">
            <li><a href="/news/2.html" id="ctl00_show_70" title="德昌县网站建设">德昌县网站建设</a></li><li><a href="/news/3.html" id="ctl00_show_70" title="德昌县网站设计">德昌县网站设计</a></li><li><a href="/news/5.html" id="ctl00_show_70" title="德昌县网站制作">德昌县网站制作</a></li><li><a href="/news/6.html" id="ctl00_show_70" title="德昌县网站优化">德昌县网站优化</a></li>          </ul>
                </li>
                <li class="dropdown"><a href="/Knowledge/" class="dropdown-toggle">知识学堂 <b class="caret"></b></a>
                    <ul class="child-menu">
            <li><a href="/websitelist/8.html" title="德昌县网站建设知识">德昌县网站建设知识</a></li><li><a href="/websitelist/9.html" title="德昌县网站设计知识">德昌县网站设计知识</a></li><li><a href="/websitelist/10.html" title="德昌县微信营销知识">德昌县微信营销知识</a></li><li><a href="/websitelist/11.html" title="德昌县营销推广知识">德昌县营销推广知识</a></li>          </ul>
                </li>
                <li class="dropdown"><a href="/about/" class="dropdown-toggle" rel="nofollow">关于我们 <b class="caret"></b></a>
                    <ul class="child-menu">
                        <li><a href="/about/jj/index.html" id="ctl00_show_1300" title="公司简介" rel="nofollow">公司简介</a></li>
                        <li><a href="/about/history/index.html" id="ctl01_show_1301" title="发展历史" rel="nofollow">发展历史</a></li>
                        <li><a href="/about/jjtd/index.html" id="ctl02_show_1302" title="精英团队" rel="nofollow">精英团队</a></li>
                        <li><a href="/about/join/" rel="nofollow">加入我们</a></li>
                        <li><a href="/about/contact/" rel="nofollow">联系翔捷宏鑫</a></li>
                    </ul>
                </li>
            </ul>
            <dl class="last-dl">
                <dt> <a href="javascript:;" title="联系我们" rel="nofollow">联系翔捷宏鑫</a> </dt>
                <dd class="conta"> <span><img src="/Public/Home/images/zg_ewm.png" width="100" /><br />
          企业微信号</span> </dd>
            </dl>
        </div>
        <div class="childcompan clearfix"> </div>
        <div class="copy">
            友情链接:
            <a href="http://m.cdxwcx.com/zuo.html" title="做网站的公司" target="_blank">做网站的公司</a>   <a href="http://www.cdfuwuqi.com/cloud/" title="云服务器" target="_blank">云服务器</a>   <a href="http://www.wjzwz.com/" title="wjzwz.com" target="_blank">wjzwz.com</a>   <a href="http://www.cdhuace.com/zhangui.html" title="成都展柜设计公司" target="_blank">成都展柜设计公司</a>   <a href="https://www.cdcxhl.com/yunying.html" title="网站改版维护" target="_blank">网站改版维护</a>   <a href="http://www.sclezhi.cn/" title="sclezhi.cn" target="_blank">sclezhi.cn</a>   <a href="http://www.gyjike.cn/" title="gyjike.cn" target="_blank">gyjike.cn</a>   <a href="http://www.cdxwcx.cn/weihu/" title="成都网站维护" target="_blank">成都网站维护</a>   <a href="http://www.mzlewan.com/" title="mzlewan.com" target="_blank">mzlewan.com</a>   <a href="http://www.ncruijie.cn/" title="ncruijie.cn" target="_blank">ncruijie.cn</a>           </div>
        <br>
        123ABC<strong> <a href="/">德昌县网站建设</a></strong>,德昌县定制网站建设——全心全意建网站公司 </div>
</div>
<script type="text/javascript" src="/Public/Home/js/meiqia.js"></script>
<script type="text/javascript" src="/Public/Home/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="/Public/Home/js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="/Public/Home/js/i.js"></script>
<script type="text/javascript" src="/Public/Home/js/script.js"></script>
<script type="text/javascript" src="/Public/Home/js/SuperSlide.js"></script>
<script type="text/javascript" src="/Public/Home/js/jquery.toTop.min.js"></script>
<script type="text/javascript" src="/Public/Home/js/num-change.js"></script>
<script type="text/javascript" src="/Public/Home/js/jquery.nicescroll.min.js"></script>
<script type="text/javascript">
    $(".menu li").eq(7).addClass("current-menu-item");
</script>
</body>
</html>
<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>