Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2006-2010 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. package com.dmdirc.addons.dns;
  23. import com.dmdirc.commandparser.CommandArguments;
  24. import com.dmdirc.commandparser.CommandManager;
  25. import com.dmdirc.commandparser.commands.GlobalCommand;
  26. import com.dmdirc.ui.interfaces.InputWindow;
  27. import java.util.Timer;
  28. import java.util.TimerTask;
  29. /**
  30. * Performs DNS lookups for nicknames, hostnames or IPs.
  31. */
  32. public final class DNSCommand extends GlobalCommand {
  33. /** Creates a new instance of DNSCommand. */
  34. public DNSCommand() {
  35. super();
  36. CommandManager.registerCommand(this);
  37. }
  38. /** {@inheritDoc} */
  39. @Override
  40. public void execute(final InputWindow origin, final boolean isSilent,
  41. final CommandArguments args) {
  42. if (args.getArguments().length == 0) {
  43. showUsage(origin, isSilent, "dns", "<IP|hostname>");
  44. return;
  45. }
  46. sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolving: " + args.getArguments()[0]);
  47. new Timer("DNS Command Timer").schedule(new TimerTask() {
  48. /** {@inheritDoc} */
  49. @Override
  50. public void run() {
  51. if (args.getArguments()[0].matches("\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b")) {
  52. sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolved: "
  53. + args.getArguments()[0] + ": "
  54. + DNSPlugin.getHostname(args.getArguments()[0]));
  55. } else {
  56. sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolved: "
  57. + args.getArguments()[0] + ": "
  58. + DNSPlugin.getIPs(args.getArguments()[0]));
  59. }
  60. }
  61. }, 0);
  62. }
  63. /** {@inheritDoc} */
  64. @Override
  65. public String getName() {
  66. return "dns";
  67. }
  68. /** {@inheritDoc} */
  69. @Override
  70. public boolean showInHelp() {
  71. return true;
  72. }
  73. /** {@inheritDoc} */
  74. @Override
  75. public String getHelp() {
  76. return "dns <IP|hostname> - Performs DNS lookup of the specified ip/hostname/nickname";
  77. }
  78. }