Skip to content

Commit

Permalink
Change resolver to nslookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitr4x committed Sep 3, 2017
1 parent 0c88a31 commit 6ae04ae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ baseplate_proxy.add_child(LegoNettools)
The nettools Lego could be triggered by various prefix.

- [x] Whois
- [x] Resolver
- [x] Nslookup
- [x] DNS
- [ ] Trace
- [x] Ping
Expand All @@ -62,9 +62,9 @@ The nettools Lego could be triggered by various prefix.

` !ping {target}`

#### Resolver
#### Nslookup

` !resolver {--host | --nslookup} {target}`
` !nslookup {target}`

#### Dns

Expand Down
5 changes: 3 additions & 2 deletions legos/nettools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def listening_for(message):
"""

if Utilities.isNotEmpty(message['text']):
cmds = ['!whois', '!geoloc', '!ping', '!resolver', '!dns']
cmds = ['!whois', '!geoloc', '!ping', '!nslookup', '!dns']
return message['text'].split()[0] in cmds

def handle(self, message):
Expand Down Expand Up @@ -107,7 +107,8 @@ def get_help():
str: Helper
"""

help_text = '[!whois, !geoloc, !ping, !resolver, !dns]'\
help_text = '[!whois, !geoloc, !ping, !nslookup'\
', !dns]'\
' for further information'

return help_text
24 changes: 9 additions & 15 deletions legos/tools/Resolver.py → legos/tools/Nslookup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

import re
import socket

from Legobot.Utilities import Utilities as utils
Expand All @@ -9,7 +10,7 @@
__copyright__ = "Copyright 2017, Legobot"


class Resolver(ToolScheme):
class Nslookup(ToolScheme):
"""This class allows resolving the IP address from a domain name as well as
the reverse process.
"""
Expand All @@ -18,23 +19,16 @@ def __init__(self, args):
if utils.isNotEmpty(args):
super().__init__(args)

self.fncs = {
'host': self._host,
'nslookup': self._nslookup
}

def run(self):
if utils.isNotEmpty(self.target):
if len(self.cmds) > 0:
for cmd in self.cmds:
try:
return self.fncs[cmd]()
except KeyError:
return 'Command unknown: ' + cmd
if re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", self.target):
return self._getIP()
else:
return self._getDomainName()
else:
return self.getHelp()

def _host(self):
def _getDomainName(self):
"""Retrieve the IP address corresponding to a domain name.
Args:
Expand All @@ -48,7 +42,7 @@ def _host(self):
except:
return 'Host cannot be resolved'

def _nslookup(self):
def _getIP(self):
"""Retrieve the domain name corresponding to an IP address.
Args:
Expand All @@ -63,4 +57,4 @@ def _nslookup(self):
return 'IP address cannot be resolved'

def getHelp(self):
return " !resolver {--host | --nslookup} {target}"
return " !nslookup {target}"

0 comments on commit 6ae04ae

Please sign in to comment.