mirror of https://github.com/secdev/scapy.git
[Windows] Whois support (#474)
* Fix whois on Windows * Better whois server and parsing * Small fixes
This commit is contained in:
parent
97af816569
commit
edd94bc751
|
@ -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,7 +38,11 @@ class IPTools(object):
|
|||
"""Add more powers to a class with an "src" attribute."""
|
||||
__slots__ = []
|
||||
def whois(self):
|
||||
os.system("whois %s" % self.src)
|
||||
"""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]
|
||||
t.sort()
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
General utility functions.
|
||||
"""
|
||||
|
||||
import os,sys,socket,types
|
||||
import random,time
|
||||
import gzip,zlib,cPickle
|
||||
import re,struct,array
|
||||
import os, sys, socket, types
|
||||
import random, time
|
||||
import gzip, zlib, cPickle
|
||||
import re, struct, array
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
|
@ -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:])
|
||||
|
|
Loading…
Reference in New Issue