成都网站建设设计

将想法与焦点和您一起共享

http_banner获取2.0

更新如下

创新互联公司2013年至今,公司以网站制作、网站建设、系统开发、网络推广、文化传媒、企业宣传、平面广告设计等为主要业务,适用行业近百种。服务企业客户近1000家,涉及国内多个省份客户。拥有多年网站建设开发经验。为企业提供专业的网站建设、创意设计、宣传推广等服务。 通过专业的设计、独特的风格,为不同客户提供各种风格的特色服务。

  1. 端口可自定义 默认80

  2. 线程可自定义 默认10

  3. 使用了队列存消息

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


lock = Lock()

q = Queue.Queue()

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
	第二步使用chardect智能匹配
	'''
	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():

	while True:
		try:
			if q.qsize() == 0:
				break;
			ip = q.get()
			
			url='http://%s:%s'%(ip,port)
			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
			#获取webserver信息
			Server=url.headers['server'][0:13]
			#获取title
			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


def main(ips,threads=10):
	if '-' in ips:
		start, end = ips.split('-')
		startlong = ip2int(start)
		endlong = ip2int(end)
		ips = netaddr.IPRange(start,end)
		for ip in list(ips):
			q.put(str(ip))
	elif '/'	in ips:
		ips = netaddr.IPNetwork(ips)
		for ip in ips:
			q.put(str(ip))
			
	ths = []
	for i in xrange(threads):
		th = Thread(target=http_banner,name='thread'+str(i))
		th.start()
		ths.append(th)
		
if __name__ == '__main__':
	parser = optparse.OptionParser('usage: %prog [options] target')
	parser.add_option('-p', '--port', dest='port', default='80',type='string', help='Port.default = 80')
	parser.add_option('-t', '--threads', dest='threads_num',default=10, type='int',help='Number of threads. default = 10')
	(options,args) = parser.parse_args()
	if len(args) < 1:
		parser.print_help()
		print 'usage: python %s 218.92.227.1-218.92.227.254'%os.path.basename(sys.argv[0])
		print 'usage: python %s 218.92.227.1/24 '%os.path.basename(sys.argv[0])
		print 'usage: python %s 218.92.227.1/24 -p 8080'%os.path.basename(sys.argv[0])
		print 'usage: python %s 218.92.227.1/24 -t 100 -p 8080'%os.path.basename(sys.argv[0])

		sys.exit(0)
	ips=args[0]
	port=options.port
	threads = options.threads_num
	main(ips,int(threads))	
	</pre><p></p><p></p>            
            
                                <br>
                    网站题目:http_banner获取2.0                    <br>
                    分享路径:<a href="http://chengdu.cdxwcx.cn/article/jehosh.html">http://chengdu.cdxwcx.cn/article/jehosh.html</a>
                </div>
            </div>
        </div>
        <!--左边end-->
        <!--右边begin-->
        <div class="news_r">
            <div class="news_t"><h2 class="h2">其他资讯</h2></div>
            <div class="news_ul3">
                <ul>
                    <li>
                            <a href="/article/gcicph.html">
                                <h3 class="h3">linux系统关机命令有哪些</h3>
                            </a>
                        </li><li>
                            <a href="/article/gcicep.html">
                                <h3 class="h3">喜推双核心智能小程序跨平台运行引爆SaaS市场</h3>
                            </a>
                        </li><li>
                            <a href="/article/gcicge.html">
                                <h3 class="h3">GlusterFS的部署和应用方法</h3>
                            </a>
                        </li><li>
                            <a href="/article/gcicpo.html">
                                <h3 class="h3">mysqlfabric的概念是什么</h3>
                            </a>
                        </li><li>
                            <a href="/article/gcicpi.html">
                                <h3 class="h3">云服务器创建实例是指什么</h3>
                            </a>
                        </li>                </ul>
            </div>
        </div>
        <!--右边end-->
        <div class="c_l"></div>
    </div>
</div>
<!--正文end-->
<!--尾部begin-->
<!--尾部begin-->
<footer>
    <div class="f_bg">
        <div class="wrap">
            <div class="links">
                <h2 class="h2">甜橘子解决方案<a href="/solution/" title="更多" class="more">更多+</a></h2>
                <ul>
                    <li><a href="/solution/xiaochengxu.html" title="小程序定制解决方案">小程序定制解决方案</a></li>
                    <li><a href="/solution/qiyewz.html" title="企业网站建设解决方案">企业网站建设解决方案</a></li>
                    <li><a href="/solution/menhuwz.html" title="行业门户网站建设解决方案">行业门户网站建设解决方案</a></li>
                    <li><a href="/solution/yingxiaowz.html" title="营销型网站建设解决方案">营销型网站建设解决方案</a></li>
                    <li><a href="/solution/waimaowz.html" title="外贸网站建设解决方案">外贸网站建设解决方案</a></li>
                    <li><a href="/solution/pingpaiwz.html" title="品牌形象网站建设解决方案">品牌形象网站建设解决方案</a></li>
                    <li><a href="/solution/dianziwz.html" title="数码、电子产品网站建设解决方案">数码、电子产品网站建设解决方案</a></li>
                    <li><a href="/solution/jituanwz.html" title="集团、上市企业网站建设解决方案">集团、上市企业网站建设解决方案</a></li>
                    <li><a href="/solution/dichanwz.html" title="房地产、地产项目网站建设解决方案">房地产、地产项目网站建设解决方案</a></li>
                    <li><a href="/solution/zhubaowz.html" title="珠宝高端奢侈品网站建设解决方案">珠宝高端奢侈品网站建设解决方案</a></li>
                </ul>
            </div>
            <div class="links w2">
                <h2 class="h2">我们的实力<a href="/about/" title="更多" class="more">更多+</a></h2>
                <ul>
                    <li>10年专业互联网服务经验</li>
                    <li>成都高端建站设计团队</li>
                    <li>资深行业分析策划</li>
                    <li>B2C营销型网站建设者</li>
                    <li>前沿视觉设计、研发能力</li>
                    <li>前端代码深度符合SEO优化</li>
                    <li>成都市高新技术企业证书</li>
                    <li>具有完备的项目管理</li>
                    <li>完善的售后服务体系</li>
                    <li>深厚的网络运营经验</li>
                    <li>时刻新技术研发能力</li>
                    <li>16个网站系统软件著作权</li>
                </ul>
            </div>
            <div class="f_div2_r">
                <h2 class="h2">关于甜橘子<a href="/about/" title="更多" class="more">更多+</a></h2>
                甜橘子网站设计,为客户量身定制各类网站建设业务,包括企业型、电子商务型、行业门户型、品牌建立型等各类网站,实战经验丰富,成功案例众多。以客户利益为出发点,甜橘子网站制作为客户规划、定制符合企业需求、带有营销价值的建站方案,提供从网站前期定位分析策划到网站界面设计... </div>
            <div class="c_l"></div>
        </div>
        <div class="wrap">
            <div class="f_div3"> <span class="l">成都网站制作案例©2020 甜橘子设计 版权所有  | <a href="http://chengdu.cdxwcx.cn" target="_blank">甜橘子网站设计</a><a href="http://chengdu.cdxwcx.cn" target="_blank">chengdu.cdxwcx.cn</a></span> <span class="r"><a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">蜀ICP备11025516号</a></span> </div>
        </div>
    </div>
</footer>
<!--尾部end-->
<script language="javascript" src="/Public/Home/js/foot.js"></script>
<!--尾部end-->
<!--侧边栏begin-->
<div class="side">
    <ul>
        <li id="qqonline_xbceo"><a href="tencent://message/?uin=631063699&Site=&Menu=yes"><i class="bgs1"></i>QQ咨询</a></li>
        <li class="shangqiao"><a href="tencent://message/?uin=532337155&Site=&Menu=yes" title="在线咨询">
            <div><i class="bgs2"></i>在线咨询</div>
        </a></li>
        <li class="sideewm"><i class="bgs3"></i>官方微信
            <div class="ewBox"></div>
        </li>
        <li class="sideetel"><i class="bgs4"></i>联系电话
            <div class="telBox">
                <dd class="bgs1"><span>座机</span><a href="tel:028-86922220" target="_blank">028-86922220</a></dd>
                <dd class="bgs2"><span>手机</span><a href="tel:13518219792" target="_blank">13518219792</a></dd>
            </div>
        </li>
        <li class="sidetop" onClick="goTop()" id="sidetop"><i class="bgs6"></i>返回顶部</li>
    </ul>
</div>
<script type="text/javascript">
    $('.sideewm').hover(function(){
        $('.ewBox').stop().fadeIn();
    },function(){
        $('.ewBox').stop().fadeOut();
    });
    $('.sideetel').hover(function(){
        $('.telBox').stop().fadeIn();
    },function(){
        $('.telBox').stop().fadeOut();
    });
    $(".con_id 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);
        }
    });
</script>
<!-- WPA start -->
<!-- WPA end -->
<!--侧边栏end-->
</body>
</html>