Skip to content
Snippets Groups Projects
Commit edd94bc7 authored by gpotter2's avatar gpotter2 Committed by Guillaume Valadon
Browse files

[Windows] Whois support (#474)

* Fix whois on Windows

* Better whois server and parsing

* Small fixes
parent 97af8165
No related branches found
No related tags found
No related merge requests found
......@@ -77,7 +77,8 @@ class Net(Gen):
self.repr=net
self.parsed,self.netmask = self._parse_net(net)
def __str__(self):
return self.repr
def __iter__(self):
for d in xrange(*self.parsed[3]):
......
......@@ -16,6 +16,7 @@ from scapy.base_classes import Gen
from scapy.data import *
from scapy.layers.l2 import *
from scapy.config import conf
from scapy.consts import WINDOWS
from scapy.fields import *
from scapy.packet import *
from scapy.volatile import *
......@@ -23,6 +24,7 @@ from scapy.sendrecv import sr,sr1,srp1
from scapy.plist import PacketList,SndRcvList
from scapy.automaton import Automaton,ATMT
from scapy.error import warning
from scapy.utils import whois
import scapy.as_resolvers
......@@ -36,6 +38,10 @@ class IPTools(object):
"""Add more powers to a class with an "src" attribute."""
__slots__ = []
def whois(self):
"""whois the source and print the output"""
if WINDOWS:
print whois(self.src)
else:
os.system("whois %s" % self.src)
def ottl(self):
t = [32,64,128,255]+[self.ttl]
......
......@@ -1275,3 +1275,34 @@ def make_lined_table(*args, **kargs):
def make_tex_table(*args, **kargs):
__make_table(lambda l: "%s", lambda l: "& %s", "\\\\", seplinefunc=lambda a,x:"\\hline", *args, **kargs)
###############################################
### WHOIS CLIENT (not available on windows) ###
###############################################
def whois(ip_address):
"""Whois client for Python"""
whois_ip = str(ip_address)
try:
query = socket.gethostbyname(whois_ip)
except:
query = whois_ip
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("whois.ripe.net", 43))
s.send(query + "\r\n")
answer = ''
while True:
d = s.recv(4096)
answer += d
if not d:
break
s.close()
ignore_tag = "remarks:"
# ignore all lines starting with the ignore_tag
lines = [ line for line in answer.split("\n") if not line or (line and not line.startswith(ignore_tag))]
# remove empty lines at the bottom
for i in range(1, len(lines)):
if not lines[-i].strip():
del lines[-i]
else:
break
return "\n".join(lines[3:])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment