mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 17:38:59 +00:00
FS-3110 --comment-only phase 1 to replace udns with ldns in mod_enum may need to rerun bootstrap
This commit is contained in:
56
libs/ldns/contrib/python/examples/ldns-axfr.py
Executable file
56
libs/ldns/contrib/python/examples/ldns-axfr.py
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/python
|
||||
# vim:fileencoding=utf-8
|
||||
#
|
||||
# AXFR client with IDN (Internationalized Domain Names) support
|
||||
#
|
||||
|
||||
import ldns
|
||||
import encodings.idna
|
||||
|
||||
def utf2name(name):
|
||||
return '.'.join([encodings.idna.ToASCII(a) for a in name.split('.')])
|
||||
def name2utf(name):
|
||||
return '.'.join([encodings.idna.ToUnicode(a) for a in name.split('.')])
|
||||
|
||||
|
||||
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
|
||||
|
||||
#addr = ldns.ldns_get_rr_list_addr_by_name(resolver, "zone.nic.cz", ldns.LDNS_RR_CLASS_IN, ldns.LDNS_RD);
|
||||
addr = resolver.get_addr_by_name("zone.nic.cz", ldns.LDNS_RR_CLASS_IN, ldns.LDNS_RD);
|
||||
if (not addr):
|
||||
raise Exception("Can't retrieve server address")
|
||||
|
||||
print "Addr_by_name:",str(addr).replace("\n","; ")
|
||||
|
||||
#remove all nameservers
|
||||
while resolver.pop_nameserver():
|
||||
pass
|
||||
|
||||
#insert server addr
|
||||
for rr in addr.rrs():
|
||||
resolver.push_nameserver_rr(rr)
|
||||
|
||||
#AXFR transfer
|
||||
status = resolver.axfr_start(utf2name(u"háčkyčárky.cz"), ldns.LDNS_RR_CLASS_IN)
|
||||
if status != ldns.LDNS_STATUS_OK:
|
||||
raise Exception("Can't start AXFR. Error: %s" % ldns.ldns_get_errorstr_by_id(status))
|
||||
|
||||
#Print results
|
||||
while True:
|
||||
rr = resolver.axfr_next()
|
||||
if not rr:
|
||||
break
|
||||
|
||||
rdf = rr.owner()
|
||||
if (rdf.get_type() == ldns.LDNS_RDF_TYPE_DNAME):
|
||||
print "RDF owner: type=",rdf.get_type_str(),"data=",name2utf(str(rdf))
|
||||
else:
|
||||
print "RDF owner: type=",rdf.get_type_str(),"data=",str(rdf)
|
||||
print " RR type=", rr.get_type_str()," ttl=",rr.ttl()
|
||||
for rdf in rr.rdfs():
|
||||
if (rdf.get_type() == ldns.LDNS_RDF_TYPE_DNAME):
|
||||
print " RDF: type=",rdf.get_type_str(),"data=",name2utf(str(rdf))
|
||||
else:
|
||||
print " RDF: type=",rdf.get_type_str(),"data=",str(rdf)
|
||||
|
||||
print
|
8
libs/ldns/contrib/python/examples/ldns-buf.py
Executable file
8
libs/ldns/contrib/python/examples/ldns-buf.py
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import ldns
|
||||
|
||||
buf = ldns.ldns_buffer(1024)
|
||||
buf.printf("Test buffer")
|
||||
print buf
|
||||
|
45
libs/ldns/contrib/python/examples/ldns-dnssec.py
Executable file
45
libs/ldns/contrib/python/examples/ldns-dnssec.py
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
import ldns
|
||||
import sys
|
||||
|
||||
debug = True
|
||||
|
||||
# Check args
|
||||
argc = len(sys.argv)
|
||||
name = "www.nic.cz"
|
||||
if argc < 2:
|
||||
print "Usage:", sys.argv[0], "domain [resolver_addr]"
|
||||
sys.exit(1)
|
||||
else:
|
||||
name = sys.argv[1]
|
||||
|
||||
# Create resolver
|
||||
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
|
||||
resolver.set_dnssec(True)
|
||||
|
||||
# Custom resolver
|
||||
if argc > 2:
|
||||
# Clear previous nameservers
|
||||
ns = resolver.pop_nameserver()
|
||||
while ns != None:
|
||||
ns = resolver.pop_nameserver()
|
||||
ip = ldns.ldns_rdf.new_frm_str(sys.argv[2], ldns.LDNS_RDF_TYPE_A)
|
||||
resolver.push_nameserver(ip)
|
||||
|
||||
# Resolve DNS name
|
||||
pkt = resolver.query(name, ldns.LDNS_RR_TYPE_A, ldns.LDNS_RR_CLASS_IN)
|
||||
if pkt and pkt.answer():
|
||||
|
||||
# Debug
|
||||
if debug:
|
||||
print "NS returned:", pkt.get_rcode(), "(AA: %d AD: %d)" % ( pkt.ad(), pkt.ad() )
|
||||
|
||||
# SERVFAIL indicated bogus name
|
||||
if pkt.get_rcode() is ldns.LDNS_RCODE_SERVFAIL:
|
||||
print name, "is bogus"
|
||||
|
||||
# Check AD (Authenticated) bit
|
||||
if pkt.get_rcode() is ldns.LDNS_RCODE_NOERROR:
|
||||
if pkt.ad(): print name, "is secure"
|
||||
else: print name, "is insecure"
|
36
libs/ldns/contrib/python/examples/ldns-higher.py
Executable file
36
libs/ldns/contrib/python/examples/ldns-higher.py
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/python
|
||||
import ldns
|
||||
|
||||
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
|
||||
|
||||
dnn = ldns.ldns_dname("www.google.com")
|
||||
print dnn.get_type_str(), dnn
|
||||
|
||||
dna = ldns.ldns_rdf.new_frm_str("74.125.43.99",ldns.LDNS_RDF_TYPE_A)
|
||||
print dna.get_type_str(), dna
|
||||
|
||||
name = resolver.get_name_by_addr(dna)
|
||||
if (not name): raise Exception("Can't retrieve server name")
|
||||
for rr in name.rrs():
|
||||
print rr
|
||||
|
||||
name = resolver.get_name_by_addr("74.125.43.99")
|
||||
if (not name): raise Exception("Can't retrieve server name")
|
||||
for rr in name.rrs():
|
||||
print rr
|
||||
|
||||
addr = resolver.get_addr_by_name(dnn)
|
||||
if (not addr): raise Exception("Can't retrieve server address")
|
||||
for rr in addr.rrs():
|
||||
print rr
|
||||
|
||||
addr = resolver.get_addr_by_name("www.google.com")
|
||||
if (not addr): raise Exception("Can't retrieve server address")
|
||||
for rr in addr.rrs():
|
||||
print rr
|
||||
|
||||
hosts = ldns.ldns_rr_list.new_frm_file("/etc/hosts")
|
||||
if (not hosts): raise Exception("Can't retrieve the content of file")
|
||||
for rr in hosts.rrs():
|
||||
print rr
|
||||
|
46
libs/ldns/contrib/python/examples/ldns-keygen.py
Executable file
46
libs/ldns/contrib/python/examples/ldns-keygen.py
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# This example shows how to generate public/private key pair
|
||||
#
|
||||
import ldns
|
||||
|
||||
algorithm = ldns.LDNS_SIGN_DSA
|
||||
bits = 512
|
||||
|
||||
ldns.ldns_init_random(open("/dev/random","rb"), (bits+7)//8)
|
||||
|
||||
domain = ldns.ldns_dname("example.")
|
||||
|
||||
#generate a new key
|
||||
key = ldns.ldns_key.new_frm_algorithm(algorithm, bits);
|
||||
print key
|
||||
|
||||
#set owner
|
||||
key.set_pubkey_owner(domain)
|
||||
|
||||
#create the public from the ldns_key
|
||||
pubkey = key.key_to_rr()
|
||||
#previous command is equivalent to
|
||||
# pubkey = ldns.ldns_key2rr(key)
|
||||
print pubkey
|
||||
|
||||
#calculate and set the keytag
|
||||
key.set_keytag(ldns.ldns_calc_keytag(pubkey))
|
||||
|
||||
#build the DS record
|
||||
ds = ldns.ldns_key_rr2ds(pubkey, ldns.LDNS_SHA1)
|
||||
print ds
|
||||
|
||||
owner, tag = pubkey.owner(), key.keytag()
|
||||
|
||||
#write public key to .key file
|
||||
fw = open("key-%s-%d.key" % (owner,tag), "wb")
|
||||
pubkey.print_to_file(fw)
|
||||
|
||||
#write private key to .priv file
|
||||
fw = open("key-%s-%d.private" % (owner,tag), "wb")
|
||||
key.print_to_file(fw)
|
||||
|
||||
#write DS to .ds file
|
||||
fw = open("key-%s-%d.ds" % (owner,tag), "wb")
|
||||
ds.print_to_file(fw)
|
15
libs/ldns/contrib/python/examples/ldns-mx.py
Executable file
15
libs/ldns/contrib/python/examples/ldns-mx.py
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# MX is a small program that prints out the mx records for a particular domain
|
||||
#
|
||||
import ldns
|
||||
|
||||
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
|
||||
|
||||
pkt = resolver.query("nic.cz", ldns.LDNS_RR_TYPE_MX,ldns.LDNS_RR_CLASS_IN)
|
||||
|
||||
if (pkt):
|
||||
mx = pkt.rr_list_by_type(ldns.LDNS_RR_TYPE_MX, ldns.LDNS_SECTION_ANSWER)
|
||||
if (mx):
|
||||
mx.sort()
|
||||
print mx
|
18
libs/ldns/contrib/python/examples/ldns-mx1.py
Executable file
18
libs/ldns/contrib/python/examples/ldns-mx1.py
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# MX is a small program that prints out the mx records for a particular domain
|
||||
#
|
||||
import ldns
|
||||
|
||||
dname = ldns.ldns_dname("nic.cz")
|
||||
print dname
|
||||
|
||||
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
|
||||
|
||||
pkt = resolver.query(dname, ldns.LDNS_RR_TYPE_MX,ldns.LDNS_RR_CLASS_IN)
|
||||
|
||||
if (pkt):
|
||||
mx = pkt.rr_list_by_type(ldns.LDNS_RR_TYPE_MX, ldns.LDNS_SECTION_ANSWER)
|
||||
if (mx):
|
||||
mx.sort()
|
||||
print mx
|
19
libs/ldns/contrib/python/examples/ldns-mx2.py
Executable file
19
libs/ldns/contrib/python/examples/ldns-mx2.py
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# MX is a small program that prints out the mx records for a particular domain
|
||||
#
|
||||
import ldns
|
||||
|
||||
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
|
||||
|
||||
pkt = resolver.query("nic.cz", ldns.LDNS_RR_TYPE_MX,ldns.LDNS_RR_CLASS_IN)
|
||||
if (pkt) and (pkt.answer()):
|
||||
|
||||
for rr in pkt.answer().rrs():
|
||||
if (rr.get_type() != ldns.LDNS_RR_TYPE_MX):
|
||||
continue
|
||||
|
||||
rdf = rr.owner()
|
||||
print rdf," ",rr.ttl()," ",rr.get_class_str()," ",rr.get_type_str()," ",
|
||||
print " ".join(str(rdf) for rdf in rr.rdfs())
|
||||
|
17
libs/ldns/contrib/python/examples/ldns-newpkt.py
Executable file
17
libs/ldns/contrib/python/examples/ldns-newpkt.py
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import ldns
|
||||
|
||||
pkt = ldns.ldns_pkt.new_query_frm_str("www.google.com",ldns.LDNS_RR_TYPE_ANY, ldns.LDNS_RR_CLASS_IN, ldns.LDNS_QR | ldns.LDNS_AA)
|
||||
|
||||
rra = ldns.ldns_rr.new_frm_str("www.google.com. IN A 192.168.1.1",300)
|
||||
rrb = ldns.ldns_rr.new_frm_str("www.google.com. IN TXT Some\ Description",300)
|
||||
|
||||
list = ldns.ldns_rr_list()
|
||||
if (rra): list.push_rr(rra)
|
||||
if (rrb): list.push_rr(rrb)
|
||||
|
||||
pkt.push_rr_list(ldns.LDNS_SECTION_ANSWER, list)
|
||||
|
||||
print "Packet:"
|
||||
print pkt
|
65
libs/ldns/contrib/python/examples/ldns-signzone.py
Executable file
65
libs/ldns/contrib/python/examples/ldns-signzone.py
Executable file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/python
|
||||
# This example shows how to sign a given zone file with private key
|
||||
|
||||
import ldns
|
||||
import sys, os, time
|
||||
|
||||
#private key TAG which identifies the private key
|
||||
#use ldns-keygen.py in order to obtain private key
|
||||
keytag = 30761
|
||||
|
||||
# Read zone file
|
||||
#-------------------------------------------------------------
|
||||
|
||||
zone = ldns.ldns_zone.new_frm_fp(open("zone.txt","r"), None, 0, ldns.LDNS_RR_CLASS_IN)
|
||||
soa = zone.soa()
|
||||
origin = soa.owner()
|
||||
|
||||
# Prepare keys
|
||||
#-------------------------------------------------------------
|
||||
|
||||
#Read private key from file
|
||||
keyfile = open("key-%s-%d.private" % (origin, keytag), "r");
|
||||
key = ldns.ldns_key.new_frm_fp(keyfile)
|
||||
|
||||
#Read public key from file
|
||||
pubfname = "key-%s-%d.key" % (origin, keytag)
|
||||
pubkey = None
|
||||
if os.path.isfile(pubfname):
|
||||
pubkeyfile = open(pubfname, "r");
|
||||
pubkey,_,_,_ = ldns.ldns_rr.new_frm_fp(pubkeyfile)
|
||||
|
||||
if not pubkey:
|
||||
#Create new public key
|
||||
pubkey = key.key_to_rr()
|
||||
|
||||
#Set key expiration
|
||||
key.set_expiration(int(time.time()) + 365*60*60*24) #365 days
|
||||
|
||||
#Set key owner (important step)
|
||||
key.set_pubkey_owner(origin)
|
||||
|
||||
#Insert DNSKEY RR
|
||||
zone.push_rr(pubkey)
|
||||
|
||||
# Sign zone
|
||||
#-------------------------------------------------------------
|
||||
|
||||
#Create keylist and push private key
|
||||
keys = ldns.ldns_key_list()
|
||||
keys.push_key(key)
|
||||
|
||||
#Add SOA
|
||||
signed_zone = ldns.ldns_dnssec_zone()
|
||||
signed_zone.add_rr(soa)
|
||||
|
||||
#Add RRs
|
||||
for rr in zone.rrs().rrs():
|
||||
print "RR:",str(rr),
|
||||
signed_zone.add_rr(rr)
|
||||
|
||||
added_rrs = ldns.ldns_rr_list()
|
||||
status = signed_zone.sign(added_rrs, keys)
|
||||
if (status == ldns.LDNS_STATUS_OK):
|
||||
signed_zone.print_to_file(open("zone_signed.txt","w"))
|
||||
|
15
libs/ldns/contrib/python/examples/ldns-zone.py
Executable file
15
libs/ldns/contrib/python/examples/ldns-zone.py
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/python
|
||||
import ldns
|
||||
|
||||
#Read zone from file
|
||||
zone = ldns.ldns_zone.new_frm_fp(open("zone.txt","r"), None, 0, ldns.LDNS_RR_CLASS_IN)
|
||||
print zone
|
||||
|
||||
print "SOA:", zone.soa()
|
||||
for r in zone.rrs().rrs():
|
||||
print "RR:", r
|
||||
|
||||
|
||||
zone = ldns.ldns_zone()
|
||||
#print zone
|
||||
|
15
libs/ldns/contrib/python/examples/zone.txt
Normal file
15
libs/ldns/contrib/python/examples/zone.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
$ORIGIN example.
|
||||
$TTL 600
|
||||
|
||||
example. IN SOA example. admin.example. (
|
||||
2008022501 ; serial
|
||||
28800 ; refresh (8 hours)
|
||||
7200 ; retry (2 hours)
|
||||
604800 ; expire (1 week)
|
||||
18000 ; minimum (5 hours)
|
||||
)
|
||||
|
||||
@ IN MX 10 mail.example.
|
||||
@ IN NS ns1
|
||||
@ IN NS ns2
|
||||
@ IN A 192.168.1.1
|
Reference in New Issue
Block a user