Skip to content

Commit

Permalink
0.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
wraith-wireless committed May 24, 2016
1 parent f70f9ea commit 47e5d47
Show file tree
Hide file tree
Showing 33 changed files with 153 additions and 120 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ software in furtherance of or with intent to commit any fraudulent or other ille
activities, or otherwise in violation of any applicable law, regulation or legal
agreement.

See <http://www.gnu.org/licenses/> for a copy of the GNU General Public License.
See <http://www.gnu.org/licenses/> for a copy of the GNU General Public License.
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Include license, README
# Include license, README, channels, device, pyw and user guide
include LICENSE README.md __init__.py channels.py device.py pyw.py PyRIC.pdf

# Include subdirectories
recursive-include lib net examples docs
recursive-include docs *.help *.pdf
recursive-include docs *.help
Binary file modified PyRIC.pdf
Binary file not shown.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
## Pythonic iw

## 1 DESCRIPTION:
BLUF: Stop using subprocess.Popen, regular expressions and str.find. PyRIC
is a python port of a subset of iw and python port of netlink (w.r.t nl80211
functions).
BLUF: Why use subprocess.Popen, regular expressions and str.find to interact
with your Wireless Network Interface Card. PyRIC provides the ability to
manipuate, identify and enumerate your system's cards. It is a pure python port
of a subset the functionality provided by iw, ifconfig and iwconfig. PyRIC is:
* Pythonic: No ctypes, SWIG etc. PyRIC redefines C header files as Python and
uses sockets to communicate with kernel.
* Self-sufficient: No third-party files used, PyRIC is completely self-contained
* Fast: (relatively speaking) PyRIC is faster than using iw through subprocess.Popen
* Parse(less): Get the output you without parsing output from iw. Never worry about
iw updates and rewriting your parsers.
* Easy: If you can use iw, you can use PyRIC

### a. Background
PyRIC arose out of a need in Wraith (https://github.com/wraith-wireless/wraith)
Expand Down Expand Up @@ -76,7 +84,7 @@ the following:
* get supported commands
* get supported modes
* get dev info
* get phy info (does not currently process the bands)
* get phy info
* get/set regulatory domain
* get/set mode
* add/delete interfaces
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions pyric/TODO → TODO
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
1) overall
o look at iw dev wlan0 link
o look at iw dev
o make a cli as well
2) libnl.py
o see (1) in RFI
o define attr_ops and attr_mcast_groups in nla_policy_attr
4) pyw
o add txget from iw i.e. netlink perspective
o find a better way to find the supported standards of a card
o for now, using ioctl to set ip addresses
- move everything to netlink
o Can we find the current channel of a radio in monitor mode that is actively
scanning?
o parse NL80211_ATTR_WIPHY_BANDS
o parse NL80211_ATTR_WIPHY_BANDS (have workaround currently in place)
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# root Distribution directory
# root Distribution directory
74 changes: 74 additions & 0 deletions examples/device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python
""" device.py
Example for displaying device details
"""

import argparse as ap
import pyric # pyric error (and ecode EUNDEF)
from pyric import pyw # for iw functionality
from pyric import device # for chipset/driver
from pyric.channels import rf2ch # rf to channel conversion

def execute(dev):
# ensure dev is a wireless interfaces
wifaces = pyw.winterfaces()
if dev not in wifaces:
print "Device {0} is not wireless, use one of {1}".format(dev,wifaces)

dinfo = pyw.devinfo(dev)
card = dinfo['card']
pinfo = pyw.phyinfo(card)
driver = device.ifdriver(card.dev)
chipset = device.ifchipset(driver)

msg = "Device {0}\n".format(dev)
msg += "\tDriver: {0} Chipset: {1}\n".format(driver,chipset)
msg += "\tifindex: {0}\n".format(card.idx)
msg += "\twdev: {0}\n".format(dinfo['wdev'])
msg += "\taddr: {0}\n".format(dinfo['mac'])
msg += "\tmode: {0}\n".format(dinfo['mode'])
msg += "\twiphy: {0}\n".format(card.phy)
if dinfo['mode'] == 'managed':
msg += "\tchannel: {0} (1 MHz), width: {2}, CF: {3}\n".format(rf2ch(dinfo['RF']),
dinfo['RF'],
dinfo['CHW'],
dinfo['CF'])
else:
msg += "\tDevice not associated\n"
print msg

msg = "Wiphy phy{0}\n".format(card.phy)
msg += "\tGeneration: {0}m Coverage Class: {1}\n".format(pinfo['generation'],
pinfo['cov_class'])
msg += "\tMax # scan SSIDs: {0}\n".format(pinfo['scan_ssids'])
msg += "\tRetry Short: {0}, Long: {1}\n".format(pinfo['retry_short'],
pinfo['retry_long'])
msg += "\tThreshold Frag: {0}, RTS: {1}\n".format(pinfo['frag_thresh'],
pinfo['rts_thresh'])
msg += "\tSupported Modes:\n"
for mode in pinfo['modes']:
msg += "\t * {0}\n".format(mode)
msg += "\tSupported Commands:\n"
for cmd in pinfo['commands']:
msg += "\t * {0}\n".format(cmd)
msg += "\tSupported Frequencies:\n"
for freq in pinfo['freqs']:
msg += "\t * {0}\n".format(freq)

print msg

if __name__ == '__main__':
# create arg parser and parse command line args
print "Wireless Device Info Display using PyRIC v{0}".format(pyric.__version__)
argp = ap.ArgumentParser(description="Wireless Device Data")
argp.add_argument('-d','--dev',help="Wireless Device")
args = argp.parse_args()
try:
dev = args.dev
if dev is None:
print "usage: python device.py -d <dev>"
else:
execute(dev)
except pyric.error as e:
print e
4 changes: 2 additions & 2 deletions examples/pentest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def execute(dev):
try:
dev = args.dev
if dev is None:
print "usage: python pentest -d <dev> -v <vdev>"
print "usage: python pentest.py -d <dev>"
else:
execute(dev)
except pyric.error as e:
print e
print e
4 changes: 3 additions & 1 deletion pyric/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@
- added devcmds in pyw
- annotated (in comments) if fcts needed root privileges
- added functions to get/set ip address, netmask and broadcast
- fixed PEP8 errors
- made worked around for pulling supported freqs out NL80211_ATTR_WIPHY_BANDS
"""

__name__ = 'pyric'
__license__ = 'GPLv3'
__version__ = '0.0.7'
__version__ = '0.0.8'
__date__ = 'April 2016'
__author__ = 'Dale Patterson'
__maintainer__ = 'Dale Patterson'
Expand Down
3 changes: 1 addition & 2 deletions pyric/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
Only defines ISM 2.4Ghz and UNII 5Ghz
Defines ISM 2.4Ghz and UNII 5Ghz frequencies and channels
"""

__name__ = 'channels'
Expand Down
8 changes: 8 additions & 0 deletions pyric/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
phypath = '/sys/class/ieee80211/{0}' # format w/ phyiscal name
# NOTE phypath + index contains the ifindex (sometimes)

def ifcard(dev):
"""
:param dev: device name
:returns: tuple t = (driver,chipset)
"""
driver = ifdriver(dev)
return driver, ifchipset(driver)

def ifdriver(dev):
"""
:param dev: device name
Expand Down
2 changes: 1 addition & 1 deletion pyric/docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
desc: PyRIC and nl80211 documentation/help
includes: nl80211.cmd
changes:
o Began work on User Guide
o User Guide complete (mostly)
"""

__name__ = 'docs'
Expand Down
2 changes: 1 addition & 1 deletion pyric/docs/attributes.help

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyric/docs/commands.help

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pyric/docs/nlhelp.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/usr/bin/env python
""" nlhelp.py: nl80211 help functions
A set of functions to assist in finding info on nl80211 commands and attributes.
These are stored in the "data" files commands.help and attributes.help which are
json files.
Copyright (C) 2016 Dale V. Patterson (wraith.wireless@yandex.com)
This program is free software: you can redistribute it and/or modify it under
Expand All @@ -23,6 +19,10 @@
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
A set of functions to assist in finding info on nl80211 commands and attributes.
These are stored in the "data" files commands.help and attributes.help which are
json files.
"""

__name__ = 'nlhelp'
Expand Down
7 changes: 1 addition & 6 deletions pyric/docs/res/PyRIC.bib
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
% This file was created with JabRef 2.10b2.
% Encoding: UTF-8
@Misc{libnl,
Title = {Netlink Library (libnl)},
Author = {Thomas Graf},
Expand Down Expand Up @@ -48,5 +44,4 @@ @Misc{gplv3
Shorthand = {GPL},
Url = {http://www.gnu.org/licenses/gpl.html},
Version = {3}
}

}
10 changes: 9 additions & 1 deletion pyric/docs/res/PyRIC.tex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
basicstyle=\footnotesize
}

\title{PyRIC v0.0.7: User Manual}
\title{PyRIC v0.0.8: User Manual}
\author{Dale V. Patterson\\ wraith.wireless@yandex.com}

\begin{document}
Expand All @@ -98,6 +98,7 @@ \section{About PyRIC}\label{sec:About}
\item enumerate interfaces and wireless interfaces,
\item get/set regulatory domain,
\item get/set hw address,
\item get/set ip4, netmask and broadcast address
\item identify a radio's chipset and driver,
\item turn device on/off,
\item get supported standards,
Expand Down Expand Up @@ -656,6 +657,8 @@ \subsection{Constants}
\item \textbf{\_FAM80211ID\_}: Global netlink family id of nl80211. Do not touch
\item \textbf{IFTYPES}: redefined (from nl80211\_h.py) interface modes
\item \textbf{MNTRFLAGS}: redefined (from nl80211\_h.py) monitor mode flags
\item \textbf{IPADDR}: Regular Expression for ip4 address validation
\item \textbf{MACADDR}: Regular Expression for mac address validation
\end{itemize}

\subsection{Objects/Classes}
Expand Down Expand Up @@ -751,6 +754,9 @@ \subsection{Functions}
\item devdel(card,[nlsock]): (iw card.<dev> del), type: netlink, deletes dev
\begin{itemize}
\item \_hex2mac\_(v): returns a ':' separated mac address from byte stream v
\item \_hex2ip4\_(v): returns a '.' separated ip4 address from byte stream v
\item \_validip4\_(addr): determines if addr is a valid ip4 address
\item \_validmac\_(addr): determines if addr is a valid mac address
\item \_issetf\_(flags,flag): determines if flag is set in flags
\item \_setf\_(flags,flag): set flag in flags to on
\item \_unsetf\_(flags,flag): set flag in flags to off
Expand All @@ -759,6 +765,8 @@ \subsection{Functions}
\item \_ifindex\_(dev,[iosock]): returns dev's ifindex
\item \_flagsget\_(dev,[iosock]): get's the dev's interface flags
\item \_flagsset\_(dev,flags,[iosock]): set's the dev's interface flags
\item \_getfreqs\_(band): returns a list of frequencies from the packed byte string
band
\item \_iostub\_(fct,*argv): ioctl stub function, calls fct with parameter list argv
and an allocated ioctl socket
\item \_nlstub\_(fct,*argv): netlink stub function, calls fct with parameter list
Expand Down
1 change: 1 addition & 0 deletions pyric/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- remove nla_* from GENLMsg stand-alone functions as this was my original
intent where the classes should only be 'placeholders', similar to C structs
and not full blow objects
"""

__name__ = 'lib'
Expand Down
2 changes: 1 addition & 1 deletion pyric/lib/libio.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ def io_transfer(iosock,flag,ifreq):
else:
raise pyric.error(pyric.EUNDEF,e)
except Exception as e:
raise pyric.error(pyric.EUNDEF,e.args[0])
raise pyric.error(pyric.EUNDEF,e.args[0])
3 changes: 1 addition & 2 deletions pyric/lib/libnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
liberties with the below as these functions only handle nl80211 generic netlink
messages.
see http://www.carisma.slowglass.com/~tgr/libnl/doc/core.html
Provides access to netlink sockets and messages in a manner similar to libnl.
see http://www.carisma.slowglass.com/~tgr/libnl/doc/core.html
"""

Expand Down
1 change: 1 addition & 0 deletions pyric/net/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
o changed policies from list to dict
o removed nle_error related as we use python errno
o added ip4 to sockaddr and set ip4 to ifreq
"""

__name__ = 'net'
Expand Down
4 changes: 2 additions & 2 deletions pyric/net/genetlink_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
A port of genetlink.h to python. Includes as well the nla_policy for generic
netlink attributes.
A port of genetlink.h to python and defines the nla_policy for generic netlink
attributes.
"""

Expand Down
6 changes: 3 additions & 3 deletions pyric/net/if_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
A port of if.h, iw_param from wireless.h and sockaddr from socket.h to python
A port of if.h, with some definitions from iw_param, wireless.h and sockaddr
from socket.h to python
Additionally
1) imports definitions from wireless_h to check if a nic is wireless and get
Expand All @@ -50,8 +51,7 @@

__name__ = 'if_h'
__license__ = 'GPLv3'
__version__ = '0.0.3Dark' \
''
__version__ = '0.0.3'
__date__ = 'February 2016'
__author__ = 'Dale Patterson'
__maintainer__ = 'Dale Patterson'
Expand Down
14 changes: 0 additions & 14 deletions pyric/net/netlink_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,20 +320,6 @@ def nlattrhdr(alen,atype):
#NLA_HDRLEN = ((int) NLA_ALIGN(sizeof(struct nlattr)))

# defined error codes
"""
For ease of use, I define netlink errors (netlink/errno.h) here
/*
* netlink/errno.h Error Numbers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* Copyright (c) 2008 Thomas Graf <tgraf@suug.ch>
*/
"""
# only use success and failure -> using errno for other error numbers
NLE = ['Success','Unspecified failure']
NLE_SUCCESS = 0
Expand Down
2 changes: 1 addition & 1 deletion pyric/net/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def nla_datatype(policy,attr):

nla_dts["nl80211_attr"] = nl80211c.nl80211_policy

# ATT we do include the below
# ATT we do include the below as defined in nl80211_c
#nla_dts["nl80211_key"] = nl80211c.nl80211_key_policy
#nla_dts["nl80211_wowlan_trig"] = nl80211_wowlan_trig_policy
#nla_dts["nl80211_wowlan_tcp"] = nl80211_wowlan_tcp_policy
Expand Down
4 changes: 0 additions & 4 deletions pyric/net/sockios_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@
__email__ = 'wraith.wireless@yandex.com'
__status__ = 'Production'

# Linux-specific socket ioctls
#SIOCINQ = FIONREAD
#SIOCOUTQ = TIOCOUTQ # output queue size (not sent + not acked)

# Routing table calls
SIOCADDRT = 0x890B # add routing table entry
SIOCDELRT = 0x890C # delete routing table entry
Expand Down
Loading

0 comments on commit 47e5d47

Please sign in to comment.