delete some test function
This commit is contained in:
parent
d18adf7aee
commit
385d92abc8
@ -1,57 +0,0 @@
|
|||||||
import numpy as np
|
|
||||||
import random
|
|
||||||
|
|
||||||
class Distribution:
|
|
||||||
def __init__(self,vl,pl=[],dtype=np.int):
|
|
||||||
self.dtype = dtype
|
|
||||||
self.cnt = len(vl)
|
|
||||||
vlen = len(vl)
|
|
||||||
plen = len(pl)
|
|
||||||
sp = sum(pl)
|
|
||||||
if plen > vlen:
|
|
||||||
pl = pl[:vlen]
|
|
||||||
plen = vlen
|
|
||||||
if sp > 1.0:
|
|
||||||
raise Exception("Probability > 1")
|
|
||||||
if plen < vlen:
|
|
||||||
pv = 1.0 - sp
|
|
||||||
n = vlen - plen
|
|
||||||
p = pv / n
|
|
||||||
for i in range(n-1,vlen):
|
|
||||||
pl.append(p)
|
|
||||||
self.vl = vl
|
|
||||||
self.pl = pl
|
|
||||||
vp = []
|
|
||||||
vp = [1,]
|
|
||||||
i = vlen - 1
|
|
||||||
while i > 0:
|
|
||||||
vp.append(vp[vlen - i - 1] - pl[i])
|
|
||||||
i -= 1
|
|
||||||
vp.reverse()
|
|
||||||
self.vp = vp
|
|
||||||
|
|
||||||
def distri(self,value):
|
|
||||||
for v in self.vl:
|
|
||||||
print(v,(len([i for i in value if v == i])*1.0) /(len(value)*1.0))
|
|
||||||
|
|
||||||
def func(self,v):
|
|
||||||
i = 0
|
|
||||||
while i < self.cnt:
|
|
||||||
if v < self.vp[i]:
|
|
||||||
return self.vl[i]
|
|
||||||
i += 1
|
|
||||||
return self.vp[self.cnt -1]
|
|
||||||
|
|
||||||
def generator(self,count):
|
|
||||||
a = np.random.rand(count)
|
|
||||||
func = np.frompyfunc(self.func,1,1)
|
|
||||||
return func(a)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
d1 = Distribution([1,2,3,4],[.5,.24])
|
|
||||||
v = d1.generator(100000)
|
|
||||||
print('v=',v)
|
|
||||||
|
|
||||||
print(d1.distri(v))
|
|
||||||
v = d1.generator(2000000)
|
|
||||||
print(d1.distri(v))
|
|
@ -1,29 +0,0 @@
|
|||||||
import numpy as np
|
|
||||||
import random
|
|
||||||
from Distribution import Distribution
|
|
||||||
class ProbabilitySet:
|
|
||||||
def __init__(self,dset,p):
|
|
||||||
self.dset = dset
|
|
||||||
self.probiablity = p
|
|
||||||
|
|
||||||
def dataset(self):
|
|
||||||
dl = Distribution([1,0],[self.probiablity,])
|
|
||||||
v = dl.generator(len(self.dset))
|
|
||||||
m = []
|
|
||||||
for i in range(len(self.dset)):
|
|
||||||
if v[i] == 1:
|
|
||||||
m.append(self.dset)
|
|
||||||
return m
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
from timecost import TimeCost
|
|
||||||
dset = range(10000000)
|
|
||||||
pp = [0.1,0.22,0.334,0.88,0.93]
|
|
||||||
tc = TimeCost()
|
|
||||||
for p in pp:
|
|
||||||
tc.begin('dataset() %f' % p)
|
|
||||||
ps = ProbablitySet(dset,p)
|
|
||||||
d = ps.dataset()
|
|
||||||
tc.end('dataset() %f' % p)
|
|
||||||
|
|
||||||
tc.show()
|
|
@ -1,18 +0,0 @@
|
|||||||
import os,sys
|
|
||||||
from folderUtils import ProgramPath
|
|
||||||
|
|
||||||
class PublicData :
|
|
||||||
def __init__(self) :
|
|
||||||
p = ProgramPath()
|
|
||||||
# print p
|
|
||||||
self.ProgramPath = os.path.dirname(ProgramPath())
|
|
||||||
|
|
||||||
def set(self,name,value) :
|
|
||||||
setattr(self,name,value)
|
|
||||||
|
|
||||||
def get(self,name,default=None) :
|
|
||||||
return getattr(self,name,default)
|
|
||||||
|
|
||||||
public_data = PublicData()
|
|
||||||
|
|
||||||
# print 'ProgramPath=',public_data.get('ProgramPath',None)
|
|
@ -1,242 +0,0 @@
|
|||||||
import os,sys
|
|
||||||
import thread
|
|
||||||
import apsw
|
|
||||||
import time
|
|
||||||
from localefunc import *
|
|
||||||
from folderUtils import mkdir
|
|
||||||
from PublicData import public_data
|
|
||||||
from mylog import mylog
|
|
||||||
|
|
||||||
def logit(s) :
|
|
||||||
mylog('%s:%s' % (__file__,s))
|
|
||||||
|
|
||||||
class Record :
|
|
||||||
def __init__(self,data,localize=False) :
|
|
||||||
|
|
||||||
for i in data.keys() :
|
|
||||||
d = data[i]
|
|
||||||
if localize and type(d)==type('') :
|
|
||||||
d = localeString(d)
|
|
||||||
setattr(self,i.lower(),d)
|
|
||||||
|
|
||||||
def __getattr__(self,name) :
|
|
||||||
dict = self.__dict__
|
|
||||||
name = name.lower()
|
|
||||||
if name in dict.keys() :
|
|
||||||
return dict[name]
|
|
||||||
else :
|
|
||||||
raise AttributeError(name)
|
|
||||||
|
|
||||||
def __str__(self) :
|
|
||||||
a = self.__dict__
|
|
||||||
f = []
|
|
||||||
for i in a.keys() :
|
|
||||||
f.append("%s : %s" % (i,str(a[i])))
|
|
||||||
return '[%s]' % '\n'.join(f)
|
|
||||||
|
|
||||||
def str2unicode(s) :
|
|
||||||
if type(s) == type('') :
|
|
||||||
try :
|
|
||||||
ret = unicode(s,local_encoding)
|
|
||||||
return ret
|
|
||||||
except :
|
|
||||||
try :
|
|
||||||
ret = unicode(s,'utf8')
|
|
||||||
return ret
|
|
||||||
except :
|
|
||||||
return buffer(s)
|
|
||||||
return s
|
|
||||||
|
|
||||||
def unicode2str(s) :
|
|
||||||
t = type(s)
|
|
||||||
if t == type(5) :
|
|
||||||
return long(s)
|
|
||||||
if t == type(buffer('')) :
|
|
||||||
return str(s)
|
|
||||||
if t == type(u"w") :
|
|
||||||
return s.encode('utf8')
|
|
||||||
return s
|
|
||||||
|
|
||||||
def argConvert(args) :
|
|
||||||
if args==None :
|
|
||||||
return None
|
|
||||||
t = type(args)
|
|
||||||
if t==type(()) or t==type([]) :
|
|
||||||
return [str2unicode(i) for i in args]
|
|
||||||
if t==type({}) :
|
|
||||||
for i in args.keys() :
|
|
||||||
args[i] = str2unicode(args[i])
|
|
||||||
return args
|
|
||||||
return args
|
|
||||||
|
|
||||||
class SQLite3 :
|
|
||||||
|
|
||||||
def __init__(self,dbpath,localize=False) :
|
|
||||||
self.__dict__['threadMap'] = {}
|
|
||||||
self.__dict__['localize'] = localize
|
|
||||||
self.__dict__['dbpath'] = dbpath
|
|
||||||
self.results = None
|
|
||||||
self.con = None
|
|
||||||
self.cursor = None
|
|
||||||
self.sqlcmd = ''
|
|
||||||
self._connection(dbpath)
|
|
||||||
|
|
||||||
def _connection(self,dbpath=None) :
|
|
||||||
if dbpath!=None :
|
|
||||||
self.dbpath = dbpath
|
|
||||||
self.con = apsw.Connection(self.dbpath)
|
|
||||||
self.cursor = self.con.cursor()
|
|
||||||
self.result = None
|
|
||||||
self.sqlcmd = ''
|
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
|
||||||
id = thread.get_ident()
|
|
||||||
if not self.__dict__['threadMap'].has_key(id):
|
|
||||||
self.__dict__['threadMap'][id] = {}
|
|
||||||
self.threadMap[id][name] = value
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
|
||||||
id = thread.get_ident()
|
|
||||||
|
|
||||||
if not self.__dict__['threadMap'].has_key(id) :
|
|
||||||
self.__dict__['threadMap'][id] = {}
|
|
||||||
if self.__dict__['threadMap'][id].has_key(name) :
|
|
||||||
return self.__dict__['threadMap'][id][name]
|
|
||||||
raise AttributeError(name)
|
|
||||||
|
|
||||||
def tables(self) :
|
|
||||||
self.SQL("select * from sqlite_master where type='table'")
|
|
||||||
r = self.FETCH()
|
|
||||||
ts = []
|
|
||||||
while r :
|
|
||||||
ts.append(r.name)
|
|
||||||
r = self.FETCH()
|
|
||||||
return ts
|
|
||||||
|
|
||||||
def columns(self,tablenmae) :
|
|
||||||
self.SQL('select * from %s' % tablename)
|
|
||||||
self.desc = self.results.getdescription()
|
|
||||||
return desc
|
|
||||||
|
|
||||||
def FETCHALL(self) :
|
|
||||||
all=[]
|
|
||||||
r = True
|
|
||||||
while r:
|
|
||||||
r = self.FETCH()
|
|
||||||
if r :
|
|
||||||
all.append(r)
|
|
||||||
return all
|
|
||||||
|
|
||||||
def _eatCursorNext(self) :
|
|
||||||
if self.cursor==None :
|
|
||||||
return None
|
|
||||||
r = 1
|
|
||||||
while r :
|
|
||||||
try :
|
|
||||||
r = self.cursor.next()
|
|
||||||
except :
|
|
||||||
return
|
|
||||||
|
|
||||||
def SQL(self,cmd,args=(),retry=0) :
|
|
||||||
if self.con==None :
|
|
||||||
print("self.con==None")
|
|
||||||
return -1
|
|
||||||
self._eatCursorNext()
|
|
||||||
args = argConvert(args)
|
|
||||||
self.lastSQL = cmd
|
|
||||||
self.desc = None
|
|
||||||
try :
|
|
||||||
self.results = self.cursor.execute(cmd,args)
|
|
||||||
return True
|
|
||||||
except apsw.IncompleteExecutionError as e :
|
|
||||||
r = True
|
|
||||||
while r :
|
|
||||||
r = self.FETCH()
|
|
||||||
return self.SQL(cmd,args,retry + 1)
|
|
||||||
except apsw.BusyError as e:
|
|
||||||
if retry >20 :
|
|
||||||
print("execute:(",cmd,")Busy, error",e)
|
|
||||||
self.results=None
|
|
||||||
raise e
|
|
||||||
time.sleep(0.01)
|
|
||||||
return self.SQL(cmd,args,retry + 1)
|
|
||||||
except apsw.LockedError as e :
|
|
||||||
if retry >20 :
|
|
||||||
print("execute:(",cmd,")Locked, error",e)
|
|
||||||
self.results = None
|
|
||||||
raise e
|
|
||||||
time.sleep(0.01)
|
|
||||||
return self.SQL(cmd,args,retry + 1)
|
|
||||||
except apsw.ThreadingViolationError as e :
|
|
||||||
self._connection()
|
|
||||||
return self.SQL(cmd,args,retry+1)
|
|
||||||
except apsw.Error as e:
|
|
||||||
print('execute:',cmd,'error',e)
|
|
||||||
self.results = None
|
|
||||||
raise
|
|
||||||
print("sql finish")
|
|
||||||
return True
|
|
||||||
|
|
||||||
def FETCH(self) :
|
|
||||||
if self.results == None :
|
|
||||||
print("FETCH error,results==None")
|
|
||||||
return None
|
|
||||||
if self.desc == None :
|
|
||||||
try :
|
|
||||||
self.desc = self.results.getdescription()
|
|
||||||
except apsw.ExecutionCompleteError as e :
|
|
||||||
# print("getdescription error",self.lastSQL,e)
|
|
||||||
return None
|
|
||||||
except Exception as e:
|
|
||||||
print("fetch error",self.lastSQL,e)
|
|
||||||
raise
|
|
||||||
try :
|
|
||||||
desc = self.desc
|
|
||||||
d = self.results.next()
|
|
||||||
data = {}
|
|
||||||
for i in range(len(d)) :
|
|
||||||
data[desc[i][0]] = unicode2str(d[i])
|
|
||||||
return Record(data,self.localize)
|
|
||||||
except StopIteration :
|
|
||||||
# print("StopIteration error")
|
|
||||||
return None
|
|
||||||
except apsw.Error as e:
|
|
||||||
print("error happen",e,self,lastSQL)
|
|
||||||
raise
|
|
||||||
|
|
||||||
def COMMIT(self) :
|
|
||||||
self.SQL('COMMIT')
|
|
||||||
|
|
||||||
def ROLLBACK(self) :
|
|
||||||
self.SQL('ROLLBACK')
|
|
||||||
|
|
||||||
def BEGIN(self) :
|
|
||||||
self.SQL('BEGIN')
|
|
||||||
return
|
|
||||||
|
|
||||||
def CLOSE(self) :
|
|
||||||
self.con = None
|
|
||||||
self.cursor = None
|
|
||||||
|
|
||||||
|
|
||||||
def getDataBase(name) :
|
|
||||||
a_name='db_%s' % name
|
|
||||||
db = public_data.get(a_name,None)
|
|
||||||
if db==None :
|
|
||||||
dbpath = public_data.get('dbpath_%s' % name,None)
|
|
||||||
if dbpath==None :
|
|
||||||
p = public_data.get('ProgramPath',None)
|
|
||||||
if p==None:
|
|
||||||
raise Exception('public_data must has a "ProgramPath" variable')
|
|
||||||
p1 = os.path.join(p,'var')
|
|
||||||
mkdir(p1)
|
|
||||||
dbpath = os.path.join(p1,'%s.db3' % name)
|
|
||||||
public_data.set('dbpath_%s' % name,dbpath)
|
|
||||||
db = SQLite3(dbpath)
|
|
||||||
public_data.set(a_name,db)
|
|
||||||
try :
|
|
||||||
con = db.con
|
|
||||||
except :
|
|
||||||
dbpath = public_data.get('dbpath_%s' % name,None)
|
|
||||||
db._connection(dbpath)
|
|
||||||
return db
|
|
@ -1,45 +0,0 @@
|
|||||||
from twisted.enterprise.adbapi import ConnectionPool,Transaction
|
|
||||||
|
|
||||||
#import pymssql
|
|
||||||
#import ibm_db
|
|
||||||
#import cx_Oracle
|
|
||||||
|
|
||||||
def dbPool(dbdef):
|
|
||||||
pool = ConnectionPool(dbdef.driver,**dbdef.kwargs)
|
|
||||||
return pool
|
|
||||||
|
|
||||||
def dbConnect(pool):
|
|
||||||
conn = pool.connect()
|
|
||||||
#conn.as_dict = True
|
|
||||||
return conn
|
|
||||||
|
|
||||||
def dbClose(pool,conn):
|
|
||||||
pool.disconnect(conn)
|
|
||||||
|
|
||||||
def dbCursor(pool,conn):
|
|
||||||
return Transaction(pool,conn)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
from appPublic.dictObject import DictObject
|
|
||||||
dbdict= {
|
|
||||||
"driver":"pymssql",
|
|
||||||
"kwargs":{
|
|
||||||
"cp_max":30,
|
|
||||||
"cp_min":10,
|
|
||||||
"host":"localhost",
|
|
||||||
"user":"sa",
|
|
||||||
"password":"ymq123",
|
|
||||||
"database":"dzh"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dbdef = DictObject(**dbdict)
|
|
||||||
pool = dbPool(dbdef)
|
|
||||||
conn = dbConnect(pool)
|
|
||||||
cur = dbCursor(pool,conn)
|
|
||||||
|
|
||||||
for i in range(20):
|
|
||||||
r = cur.execute("insert into dbo.TQ_QT_INDEX (ID,TRADEDATE,SECODE,TMSTAMP) values(%d,'%s','0','11:22')" % (i,"2015-12-31"))
|
|
||||||
cur.close()
|
|
||||||
conn.commit()
|
|
||||||
dbClose(pool,conn)
|
|
||||||
pool.close()
|
|
188
appPublic/rc4.py
188
appPublic/rc4.py
@ -54,191 +54,9 @@ class RC4:
|
|||||||
|
|
||||||
|
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
# 需要加密的数据
|
# 需要加密的数据长度没有限制
|
||||||
data = '''hello python 爱的实打实大师大师大师的发送到发送到而非个人格个二哥而而二哥而个人各位,UDP是一种无连接对等通信协议,没有服务器和客户端概念,通信的任何一方均可通过通信原语直接和其他方通信
|
|
||||||
|
|
||||||
HOME FAQ DOCS DOWNLOAD
|
|
||||||
|
|
||||||
|
|
||||||
index
|
|
||||||
next |
|
|
||||||
previous |
|
|
||||||
Twisted 18.9.0 documentation » Twisted Names (DNS) » Developer Guides »
|
|
||||||
|
|
||||||
Creating a custom server
|
|
||||||
The builtin DNS server plugin is useful, but the beauty of Twisted Names is that you can build your own custom servers and clients using the names components.
|
|
||||||
In this section you will learn about the components required to build a simple DNS server.
|
|
||||||
You will then learn how to create a custom DNS server which calculates responses dynamically.
|
|
||||||
A simple forwarding DNS server
|
|
||||||
Lets start by creating a simple forwarding DNS server, which forwards all requests to an upstream server (or servers).
|
|
||||||
simple_server.py
|
|
||||||
# Copyright (c) Twisted Matrix Laboratories.
|
|
||||||
# See LICENSE for details.
|
|
||||||
|
|
||||||
"""
|
|
||||||
An example of a simple non-authoritative DNS server.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from twisted.internet import reactor
|
|
||||||
from twisted.names import client, dns, server
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
"""
|
|
||||||
Run the server.
|
|
||||||
"""
|
|
||||||
factory = server.DNSServerFactory(
|
|
||||||
clients=[client.Resolver(resolv='/etc/resolv.conf')]
|
|
||||||
)
|
|
||||||
|
|
||||||
protocol = dns.DNSDatagramProtocol(controller=factory)
|
|
||||||
|
|
||||||
reactor.listenUDP(10053, protocol)
|
|
||||||
reactor.listenTCP(10053, factory)
|
|
||||||
|
|
||||||
reactor.run()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
raise SystemExit(main())
|
|
||||||
In this example we are passing a client.Resolver instance to the DNSServerFactory and we are configuring that client to use the upstream DNS servers which are specified in a local resolv.conf file.
|
|
||||||
Also note that we start the server listening on both UDP and TCP ports. This is a standard requirement for DNS servers.
|
|
||||||
You can test the server using dig. For example:
|
|
||||||
$ dig -p 10053 @127.0.0.1 example.com SOA +short
|
|
||||||
sns.dns.icann.org. noc.dns.icann.org. 2013102791 7200 3600 1209600 3600
|
|
||||||
A server which computes responses dynamically
|
|
||||||
Now suppose we want to create a bespoke DNS server which responds to certain hostname queries by dynamically calculating the resulting IP address, while passing all other queries to another DNS server. Queries for hostnames matching the pattern workstation{0-9}+ will result in an IP address where the last octet matches the workstation number.
|
|
||||||
We’ll write a custom resolver which we insert before the standard client resolver. The custom resolver will be queried first.
|
|
||||||
Here’s the code:
|
|
||||||
override_server.py
|
|
||||||
# Copyright (c) Twisted Matrix Laboratories.
|
|
||||||
# See LICENSE for details.
|
|
||||||
|
|
||||||
"""
|
|
||||||
An example demonstrating how to create a custom DNS server.
|
|
||||||
|
|
||||||
The server will calculate the responses to A queries where the name begins with
|
|
||||||
the word "workstation".
|
|
||||||
|
|
||||||
Other queries will be handled by a fallback resolver.
|
|
||||||
|
|
||||||
eg
|
|
||||||
python doc/names/howto/listings/names/override_server.py
|
|
||||||
|
|
||||||
$ dig -p 10053 @localhost workstation1.example.com A +short
|
|
||||||
172.0.2.1
|
|
||||||
"""
|
|
||||||
|
|
||||||
from twisted.internet import reactor, defer
|
|
||||||
from twisted.names import client, dns, error, server
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DynamicResolver(object):
|
|
||||||
"""
|
|
||||||
A resolver which calculates the answers to certain queries based on the
|
|
||||||
query type and name.
|
|
||||||
"""
|
|
||||||
_pattern = 'workstation'
|
|
||||||
_network = '172.0.2'
|
|
||||||
|
|
||||||
def _dynamicResponseRequired(self, query):
|
|
||||||
"""
|
|
||||||
Check the query to determine if a dynamic response is required.
|
|
||||||
"""
|
|
||||||
if query.type == dns.A:
|
|
||||||
labels = query.name.name.split('.')
|
|
||||||
if labels[0].startswith(self._pattern):
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def _doDynamicResponse(self, query):
|
|
||||||
"""
|
|
||||||
Calculate the response to a query.
|
|
||||||
"""
|
|
||||||
name = query.name.name
|
|
||||||
labels = name.split('.')
|
|
||||||
parts = labels[0].split(self._pattern)
|
|
||||||
lastOctet = int(parts[1])
|
|
||||||
answer = dns.RRHeader(
|
|
||||||
name=name,
|
|
||||||
payload=dns.Record_A(address=b'%s.%s' % (self._network, lastOctet)))
|
|
||||||
answers = [answer]
|
|
||||||
authority = []
|
|
||||||
additional = []
|
|
||||||
return answers, authority, additional
|
|
||||||
|
|
||||||
|
|
||||||
def query(self, query, timeout=None):
|
|
||||||
"""
|
|
||||||
Check if the query should be answered dynamically, otherwise dispatch to
|
|
||||||
the fallback resolver.
|
|
||||||
"""
|
|
||||||
if self._dynamicResponseRequired(query):
|
|
||||||
return defer.succeed(self._doDynamicResponse(query))
|
|
||||||
else:
|
|
||||||
return defer.fail(error.DomainError())
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
"""
|
|
||||||
Run the server.
|
|
||||||
"""
|
|
||||||
factory = server.DNSServerFactory(
|
|
||||||
clients=[DynamicResolver(), client.Resolver(resolv='/etc/resolv.conf')]
|
|
||||||
)
|
|
||||||
|
|
||||||
protocol = dns.DNSDatagramProtocol(controller=factory)
|
|
||||||
|
|
||||||
reactor.listenUDP(10053, protocol)
|
|
||||||
reactor.listenTCP(10053, factory)
|
|
||||||
|
|
||||||
reactor.run()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
raise SystemExit(main())
|
|
||||||
Notice that DynamicResolver.query returns a Deferred. On success, it returns three lists of DNS records (answers, authority, additional), which will be encoded by dns.Message and returned to the client. On failure, it returns a DomainError, which is a signal that the query should be dispatched to the next client resolver in the list.
|
|
||||||
Note
|
|
||||||
The fallback behaviour is actually handled by ResolverChain.
|
|
||||||
ResolverChain is a proxy for other resolvers. It takes a list of IResolver providers and queries each one in turn until it receives an answer, or until the list is exhausted.
|
|
||||||
Each IResolver in the chain may return a deferred DomainError, which is a signal that ResolverChain should query the next chained resolver.
|
|
||||||
The DNSServerFactory constructor takes a list of authoritative resolvers, caches and client resolvers and ensures that they are added to the ResolverChain in the correct order.
|
|
||||||
Let’s use dig to see how this server responds to requests that match the pattern we specified:
|
|
||||||
$ dig -p 10053 @127.0.0.1 workstation1.example.com A +short
|
|
||||||
172.0.2.1
|
|
||||||
|
|
||||||
$ dig -p 10053 @127.0.0.1 workstation100.example.com A +short
|
|
||||||
172.0.2.100
|
|
||||||
And if we issue a request that doesn’t match the pattern:
|
|
||||||
$ dig -p 10053 @localhost www.example.com A +short
|
|
||||||
93.184.216.119
|
|
||||||
Further Reading
|
|
||||||
For simplicity, the examples above use the reactor.listenXXX APIs. But your application will be more flexible if you use the Twisted Application APIs, along with the Twisted plugin system and twistd. Read the source code of names.tap to see how the twistd names plugin works.
|
|
||||||
Table Of Contents
|
|
||||||
Creating a custom server
|
|
||||||
A simple forwarding DNS server
|
|
||||||
A server which computes responses dynamically
|
|
||||||
Further Reading
|
|
||||||
Previous topic
|
|
||||||
Creating and working with a names (DNS) server
|
|
||||||
Next topic
|
|
||||||
Examples
|
|
||||||
This Page
|
|
||||||
Show Source
|
|
||||||
Quick search
|
|
||||||
|
|
||||||
Enter search terms or a module, class or function name.
|
|
||||||
|
|
||||||
|
|
||||||
Site design
|
|
||||||
By huw.wilkins.
|
|
||||||
'''
|
|
||||||
# 密钥
|
# 密钥
|
||||||
|
data="231r3 feregrenerjk gkht324g8924gnfw k;ejkvwkjerv"
|
||||||
key = '123456'
|
key = '123456'
|
||||||
rc4 = RC4(key)
|
rc4 = RC4(key)
|
||||||
print(data)
|
print(data)
|
||||||
@ -247,4 +65,4 @@ By huw.wilkins.
|
|||||||
print(encoded_data,len(encoded_data) )
|
print(encoded_data,len(encoded_data) )
|
||||||
# 解码
|
# 解码
|
||||||
decoded_data = rc4.decode(encoded_data)
|
decoded_data = rc4.decode(encoded_data)
|
||||||
print(decoded_data)
|
print(decoded_data)
|
||||||
|
Loading…
Reference in New Issue
Block a user