⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dnsproxylookup.java~

📁 Java SIP
💻 JAVA~
字号:
/* * Copyright (c) 2001 The MITRE Corporation <srjones@mitre.org> * * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Library General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at your * option) any later version. *  * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public * License for more details. *  * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB.  If not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * *//** * Class to provide a means to lookup DNS SRV records * */package org.mitre.jsip;import java.util.*;import javax.naming.*;import javax.naming.directory.*;public class DNSProxyLookup {    private static final String domainName = "mitre.org";    private static final String dnsServer = "linus.mitre.org";    public static SipUri getProxyUri( ) throws SipProxyException {		Hashtable env = new Hashtable();	env.put( "java.naming.factory.initial", "com.sun.jndi.dns.DnsFactoryContext" );	env.put( "java.naming.provider.url", "dns://" + dnsServer + "/" + domainName );	try {	    DirContext ictx = new InitialDirContext( env );	    	    String sipName = "_sip." + domainName;	    Attributes attr = ictx.getAttributes( sipName, new String [] { "SRV" } ); 		    //	String proxyName = attr.get( "A" ); // ??????? should be a hostname	    String proxyName = "stars.mitre.org";	} catch ( NamingException ne ) {	    throw new SipProxyException( ne.toString );	}	return new SipUri( "sip:" + proxyName );    }        public static void testDNSLookup() throws NamingException {	Hashtable env = new Hashtable();	env.put( "java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory" );	env.put( "java.naming.provider.url", "dns://" + dnsServer + "/" + domainName );	DirContext ictx = new InitialDirContext( env );		String hostname = "stars";	Attributes attr = ictx.getAttributes( hostname, new String [] {"A"} );	NamingEnumeration ne = attr.getAll();		for ( ; ne.hasMore(); ) {	    Attribute at = (Attribute)ne.next();	    System.out.println( "Found attribute: " + at.getID() );	    String atVal = (String)at.get();	    System.out.println( "Attribute value is " + atVal );	}    }    public static void main( String [] argc ) {	// just test	try {	    testDNSLookup();	} catch ( NamingException nex ) {	    System.err.println( "Got a problem: " + nex );	}	System.exit(0);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -