nslookup.java

来自「基于java的电子邮件群发系统,基于java的电子邮件群发系统」· Java 代码 · 共 40 行

JAVA
40
字号
package com.cwq.batchmail.util;

import java.io.IOException;
import java.util.Hashtable;

import org.xbill.DNS.Lookup;
import org.xbill.DNS.MXRecord;
import org.xbill.DNS.Record;
import org.xbill.DNS.Type;

public class NSLookup {
	
	private Hashtable<String, String> pMXRecord;

	public NSLookup() {
		super();
		pMXRecord = new Hashtable<String, String>();
	}

	public Hashtable<String, String> getPMXRecord() {
		return pMXRecord;
	}

	public String getMXRecord(String host) throws IOException {
		String record = getPMXRecord().get(host);
		if( record != null )
			return record;
			
		Record[] records = new Lookup(host, Type.MX).run();
		if(records == null)
			throw new IOException("Could not find any MX records of " + host);
		else {
			record = ((MXRecord) records[0]).getTarget().toString();
			getPMXRecord().put(host, record);
			return record;
		}
	}

}

⌨️ 快捷键说明

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