summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Richter <Felix.Richter@syntax-fehler.de>2011-01-30 22:19:57 +0100
committerFelix Richter <Felix.Richter@syntax-fehler.de>2011-01-30 22:19:57 +0100
commit0a4dc6e293738b5bff1e94f0f36dcf4da706b34d (patch)
tree849534e5ec39426693920de2ce5c07e272aadb16
parent5fb4705362ab694eb84b21f1389c6ca6bc5e4d8a (diff)
cleaned up repository
-rw-r--r--arping.py31
-rw-r--r--main.py47
-rwxr-xr-xsnmp_users.py89
3 files changed, 0 insertions, 167 deletions
diff --git a/arping.py b/arping.py
deleted file mode 100644
index 816a3f46..00000000
--- a/arping.py
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/usr/bin/python2
-
-import logging
-log = logging.getLogger('arpingy')
-import os
-try:
- if (os.geteuid() != 0):
- raise Exception('no root permissions')
- from scapy.all import * #might throws "no such module"
-
- def arpingy(iprange="10.42.1.0/24",iface='wlan0'):
- log.debug("pinging"+ iprange)
- """Arping function takes IP Address or Network, returns nested mac/ip list"""
- try:
- conf.verb=0
- ans,unans=arping(iprange,iface=iface,timeout=1)
-
- collection = []
- for snd, rcv in ans:
- result = rcv.sprintf(r"%ARP.psrc% %Ether.src%").split()
- log.debug(result)
- collection.append(result)
- return collection
- except Exception as e:
- print ("something went wrong while arpinging " + str(e))
- return []
-
-except Exception as e:
- log.error("Cannot load arping functions!" + str(e))
- def arpingy(iprange):
- return True
diff --git a/main.py b/main.py
deleted file mode 100644
index bb463d3b..00000000
--- a/main.py
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/usr/bin/env python2
-
-import logging
-logging.basicConfig(level=logging.INFO)
-log = logging.getLogger('snmp_exchange')
-
-import pika
-import json,argparse,hashlib,sys,time
-from snmp_users import snmp_users
-
-SNMP_EXCHANGE='snmp_src'
-PROTO_VERSION='1'
-
-parser = argparse.ArgumentParser(description='Generates a list of mac-addresses currently in the network via snmp ')
-parser.add_argument('--host',default='141.31.8.11', help='AMQP host ip address')
-parser.add_argument('--port',type=int,default=5672, help='AMQP host port')
-parser.add_argument('-u','--username',default='guest', help='AMQP username')
-parser.add_argument('-p','--password',default='guest', help='AMQP password')
-parser.add_argument('-r','--repeat',type=int,default=20, help='SNMP_Polling Delay')
-parser.add_argument('--unique-key',action='store_true', help='Unique Key')
-args = parser.parse_args()
-if args.unique_key:
- print hashlib.sha1(PROTO_VERSION+args.host+str(args.port)).hexdigest()
- sys.exit(0)
-
-args = parser.parse_args()
-
-connection = pika.AsyncoreConnection(pika.ConnectionParameters(
- credentials = pika.PlainCredentials(args.username,args.password),
- host=args.host,port=args.port))
-channel = connection.channel()
-
-channel.exchange_declare(exchange=SNMP_EXCHANGE,
- type='fanout')
-
-log.info('Starting up snmp_users')
-s = snmp_users()
-print ' Sending Messages in Intervals. To exit press CTRL+C'
-while True:
- log.info("collecting data from network")
- ret = s.collect()
- data = { 'type' : 'snmp', 'subtype' : 0, 'data' : ret}
- log.debug("writing data to queue : %s" % data)
- channel.basic_publish(exchange=SNMP_EXCHANGE,
- routing_key='',
- body=json.dumps(data))
- time.sleep(args.repeat)
diff --git a/snmp_users.py b/snmp_users.py
deleted file mode 100755
index cb31dab6..00000000
--- a/snmp_users.py
+++ /dev/null
@@ -1,89 +0,0 @@
-#!/usr/bin/python2
-import subprocess,re
-import logging
-from arping import arpingy
-log = logging.getLogger('snmp_users')
-
-class snmp_users:
- mac_list = {}
-
- def __init__(self,server='10.42.0.1',community='shammunity'):
- self.server = server
- self.community = community
-
- def call_external(self):
- """ creates a list of lines produced by snmpwal
- """
- out = subprocess.Popen(
- ['snmpwalk',
- '-v2c',
- '-c',self.community,
- self.server,
- '1.3.6.1.2.1.3.1.1.2'],
- stdout=subprocess.PIPE).communicate()[0]
- return out.split('\n')
-
- def parse_output(self,output):
- """ parses output lines produced by snmpwalk"""
- for i in output:
- if i == '':
- continue
-
- ip,mac = re.sub(r'.*\.(\d+\.\d+\.\d+\.\d+) = Hex-STRING: ([ 0-9A-F]*) ',
- r'\1 : \2',i).split(' : ')
-
- verified = False
- if self.verify_data(mac,ip,arpingy(ip)):
- log.info("verfied by arping %s => %s" % (mac,ip))
- verified = True
-
- #elif self.verify_data(mac,ip,pingy(ip) ): builds up onto arp'ing...
- # log.info("verfied by fallback ping %s => %s" % (mac,ip))
- # verfied = True
-
- if verified:
- if mac in self.mac_list.keys():
- log.info( "%s already assigned for ip %s (new IP %s) " %
- ( mac ,self.mac_list[mac], ip))
- self.mac_list[mac].append ( ip)
- continue
- else:
- log.debug("%s => %s" % (mac,ip))
- self.mac_list[mac] = [ ip ]
- else:
- log.warning("Verification failed %s => %s" % (mac,ip))
-
- def verify_data(self,mac,ip,ret):
- """ Verifies ip and mac via ARP Scan """
- mac = ':'.join(mac.split())
- log.debug(ret)
-
- if type(ret) == type(True):
- return True
- elif ret != []:
- ret = ret[0]
- ret_mac = ret[1].upper()
- if ret_mac == mac:
- return True
- else:
- log.info('return mac not equal to expected, %s != %s' % (ret_mac,mac))
- else:
- return False
-
- def collect(self):
- output = self.call_external()
- self.parse_output(output)
- self.print_results()
- return self.mac_list
- def print_results(self):
- log.debug('printing results:')
- print '\n'.join([ mac + " => %s" %
- str(ips) for mac,ips in self.mac_list.items() ])
- print '%d *unique* nodes in network' % len(self.mac_list)
-
-
-if __name__ == "__main__":
- logging.basicConfig(level=logging.INFO)
- a = snmp_users()
- a.collect()
-