File Source: DNSPlugin.java
/*
P/P * Method: com.dmdirc.addons.dns.DNSPlugin__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.addons.dns;
24
25 import com.dmdirc.commandparser.CommandManager;
26 import com.dmdirc.plugins.Plugin;
27
28 import java.net.InetAddress;
29 import java.net.UnknownHostException;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
34 /**
35 * DNS plugin.
36 */
37 public final class DNSPlugin extends Plugin {
38
39 /** The DNSCommand we've registered. */
40 private DNSCommand command;
41
42 /** Creates a new instance of DNSPlugin. */
43 public DNSPlugin() {
/*
P/P * Method: void com.dmdirc.addons.dns.DNSPlugin()
*/
44 super();
45 }
46
47 /** {@inheritDoc} */
48 @Override
49 public void onLoad() {
/*
P/P * Method: void onLoad()
*
* Postconditions:
* this.command == &new DNSCommand(onLoad#1)
* new DNSCommand(onLoad#1) num objects == 1
*/
50 command = new DNSCommand();
51 }
52
53 /** {@inheritDoc} */
54 @Override
55 public void onUnload() {
/*
P/P * Method: void onUnload()
*
* Preconditions:
* init'ed(this.command)
*/
56 CommandManager.unregisterCommand(command);
57 }
58
59 /**
60 * Returns the IP(s) for a hostname.
61 *
62 * @param hostname Hostname to resolve.
63 *
64 * @return Resolved IP(s)
65 */
66 public static String getIPs(final String hostname) {
/*
P/P * Method: String getIPs(String)
*
* Presumptions:
* arr$.length@70 <= 232-1
* arr$[i$]@70 != null
* java.net.InetAddress:getAllByName(...)@70 != null
*
* Postconditions:
* java.lang.Object:toString(...)._tainted == 0
* return_value == &java.lang.Object:toString(...)
*/
67 List<String> results = new ArrayList<String>();
68
69 try {
70 final InetAddress[] ips = InetAddress.getAllByName(hostname);
71
72 for (InetAddress ip : ips) {
73 results.add(ip.getHostAddress());
74 }
75
76 } catch (UnknownHostException ex) {
77 results = new ArrayList<String>();
78 }
79
80 return results.toString();
81 }
82
83 /**
84 * Returns the hostname for an ip.
85 *
86 * @param ip IP to resolve
87 *
88 * @return Resolved hostname
89 */
90 public static String getHostname(final String ip) {
91 try {
/*
P/P * Method: String getHostname(String)
*
* Presumptions:
* java.net.InetAddress:getByName(...)@92 != null
*
* Postconditions:
* init'ed(return_value)
*/
92 return InetAddress.getByName(ip).getHostName();
93 } catch (UnknownHostException ex) {
94 return "";
95 }
96 }
97
98 }
SofCheck Inspector Build Version : 2.17854
| DNSPlugin.java |
2009-Jun-25 01:54:24 |
| DNSPlugin.class |
2009-Sep-02 17:04:15 |