| |
- builtins.Exception(builtins.BaseException)
-
- PortScannerError
- builtins.dict(builtins.object)
-
- PortScannerHostDict
- builtins.object
-
- PortScanner
- PortScannerAsync
class PortScanner(builtins.object) |
|
PortScanner allows to use nmap from python |
|
Methods defined here:
- __getitem__(self, host)
- returns a host detail
- __init__(self, nmap_search_path=('nmap', '/usr/bin/nmap', '/usr/local/bin/nmap', '/sw/bin/nmap', '/opt/local/bin/nmap'))
- Initialize the module
detects nmap on the system and nmap version
may raise PortScannerError exception if nmap is not found in the path
nmap_search_path = tupple of string where to search for nmap executable. Change this if you want to use a specific version of nmap.
- all_hosts(self)
- returns a sorted list of all hosts
- command_line(self)
- returns command line used for the scan
may raise AssertionError exception if called before scanning
- get_nmap_last_output(self)
- returns the last text output of nmap in raw text
this may be used for debugging purpose
- has_host(self, host)
- returns True if host has result, False otherwise
- listscan(self, hosts='127.0.0.1')
- do not scan but interpret target hosts and return a list a hosts
- nmap_version(self)
- returns nmap version if detected (int version, int subversion)
or (0, 0) if unknown
- scan(self, hosts='127.0.0.1', ports=None, arguments='-sV')
- Scan given hosts
May raise PortScannerError exception if nmap output something on stderr
hosts = string for hosts as nmap use it 'scanme.nmap.org' or '198.116.0-255.1-127' or '216.163.128.20/20'
ports = string for ports as nmap use it '22,53,110,143-4564'
arguments = string of arguments for nmap '-sU -sX -sC'
- scaninfo(self)
- returns scaninfo structure
{'tcp': {'services': '22', 'method': 'connect'}}
may raise AssertionError exception if called before scanning
- scanstats(self)
- returns scanstats structure
{'uphosts': '3', 'timestr': 'Thu Jun 3 21:45:07 2010', 'downhosts': '253', 'totalhosts': '256', 'elapsed': '5.79'}
may raise AssertionError exception if called before scanning
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class PortScannerAsync(builtins.object) |
|
PortScannerAsync allows to use nmap from python asynchronously
for each host scanned, callback is called with scan result for the host |
|
Methods defined here:
- __del__(self)
- Cleanup when deleted
- __init__(self)
- Initialize the module
detects nmap on the system and nmap version
may raise PortScannerError exception if nmap is not found in the path
- scan(self, hosts='127.0.0.1', ports=None, arguments='-sV', callback=None)
- Scan given hosts in a separate process and return host by host result using callback function
PortScannerError exception from standard nmap is catched and you won't know about it
hosts = string for hosts as nmap use it 'scanme.nmap.org' or '198.116.0-255.1-127' or '216.163.128.20/20'
ports = string for ports as nmap use it '22,53,110,143-4564'
arguments = string of arguments for nmap '-sU -sX -sC'
callback = callback function which takes (host, scan_data) as arguments
- still_scanning(self)
- Return True if a scan is currently running, False otherwise
- stop(self)
- Stop the current scan process
- wait(self, timeout=None)
- Wait for the current scan process to finish, or timeout
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class PortScannerHostDict(builtins.dict) |
|
Special dictionnary class for storing and accessing host scan result |
|
- Method resolution order:
- PortScannerHostDict
- builtins.dict
- builtins.object
Methods defined here:
- all_ip(self)
- returns list of ip ports
- all_protocols(self)
- returns a list of all scanned protocols
- all_sctp(self)
- returns list of sctp ports
- all_tcp(self)
- returns list of tcp ports
- all_udp(self)
- returns list of udp ports
- has_ip(self, port)
- returns True if ip port has info, False otherwise
- has_sctp(self, port)
- returns True if sctp port has info, False otherwise
- has_tcp(self, port)
- returns True if tcp port has info, False otherwise
- has_udp(self, port)
- returns True if udp port has info, False otherwise
- hostname(self)
- returns hostname
- ip(self, port)
- returns info for ip port
- sctp(self, port)
- returns info for sctp port
- state(self)
- returns host state
- tcp(self, port)
- returns info for tpc port
- udp(self, port)
- returns info for udp port
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Methods inherited from builtins.dict:
- __contains__(...)
- D.__contains__(k) -> True if D has a key k, else False
- __delitem__(...)
- x.__delitem__(y) <==> del x[y]
- __eq__(...)
- x.__eq__(y) <==> x==y
- __ge__(...)
- x.__ge__(y) <==> x>=y
- __getattribute__(...)
- x.__getattribute__('name') <==> x.name
- __getitem__(...)
- x.__getitem__(y) <==> x[y]
- __gt__(...)
- x.__gt__(y) <==> x>y
- __init__(...)
- x.__init__(...) initializes x; see help(type(x)) for signature
- __iter__(...)
- x.__iter__() <==> iter(x)
- __le__(...)
- x.__le__(y) <==> x<=y
- __len__(...)
- x.__len__() <==> len(x)
- __lt__(...)
- x.__lt__(y) <==> x<y
- __ne__(...)
- x.__ne__(y) <==> x!=y
- __repr__(...)
- x.__repr__() <==> repr(x)
- __setitem__(...)
- x.__setitem__(i, y) <==> x[i]=y
- __sizeof__(...)
- D.__sizeof__() -> size of D in memory, in bytes
- clear(...)
- D.clear() -> None. Remove all items from D.
- copy(...)
- D.copy() -> a shallow copy of D
- get(...)
- D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
- items(...)
- D.items() -> a set-like object providing a view on D's items
- keys(...)
- D.keys() -> a set-like object providing a view on D's keys
- pop(...)
- D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised
- popitem(...)
- D.popitem() -> (k, v), remove and return some (key, value) pair as a
2-tuple; but raise KeyError if D is empty.
- setdefault(...)
- D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D
- update(...)
- D.update(E, **F) -> None. Update D from dict/iterable E and F.
If E has a .keys() method, does: for k in E: D[k] = E[k]
If E lacks .keys() method, does: for (k, v) in E: D[k] = v
In either case, this is followed by: for k in F: D[k] = F[k]
- values(...)
- D.values() -> an object providing a view on D's values
Data and other attributes inherited from builtins.dict:
- __hash__ = None
- __new__ = <built-in method __new__ of type object>
- T.__new__(S, ...) -> a new object with type S, a subtype of T
- fromkeys = <built-in method fromkeys of type object>
- dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.
v defaults to None.
| |