예제 #1
0
def ValidInterface():
    avail = False
    wlan = stores.args.interface
    if stores.args.verbose: print 'Looking for: ' + wlan
    if stores.args.verbose:
        print 'Verifying wireless interface is available...'
    s = cli.execute_shell('ifconfig | grep ' + wlan)
    lines = s.splitlines()
    if stores.args.verbose: print lines

    for line in lines:
        if wlan in line:
            avail = True

    if avail:
        if stores.args.verbose: print 'Interface found.'
        return True
    else:
        if stores.args.verbose:
            print 'Looking a little deeper for that interface you asked for.'
        s2 = cli.execute_shell('ifconfig -a | grep ' + wlan)
        lines = s.splitlines()
        if stores.args.verbose: print lines
        for line in lines:
            if wlan in line:
                if stores.args.verbose:
                    print 'Interface was found...but its not up. You need to fix that.'

        if stores.args.verbose: print 'Interface NOT found anywhere.'
        return False
예제 #2
0
def ValidInterface():
	avail = False
	wlan = stores.args.interface
	if stores.args.verbose: print 'Looking for: ' + wlan
	if not "mon" in wlan:
		print 'You must select a monitor interface (ie. mon0, mon1, etc).'
		return
	if stores.args.verbose: print 'Verifying wireless interface is available...'
	s=cli.execute_shell('ifconfig | grep ' + wlan)
	lines = s.splitlines()
	if stores.args.verbose: print lines

	for line in lines:
		if wlan in line:
			avail = True

	if avail:
		if stores.args.verbose: print 'Interface found.'
		return True
	else:
		if stores.args.verbose: print 'Looking a little deeper for that interface you asked for.'
		s2=cli.execute_shell('ifconfig -a | grep ' + wlan)
		lines = s.splitlines()
		if stores.args.verbose: print lines
		for line in lines:
			if wlan in line:
				if stores.args.verbose: print 'Interface was found...but its not up. You need to fix that.'

		if stores.args.verbose: print 'Interface NOT found anywhere.'
		return False
예제 #3
0
def ValidInterface():
    avail = False
    wlan = stores.args.interface
    if stores.args.verbose: print 'Looking for: ' + wlan
    if stores.args.alreadymon and not "mon" in wlan:
        print 'You must select a monitor interface (ie. mon0, mon1, etc/whatever) if you are are going to use -m as an option.'
        return
    if stores.args.verbose:
        print 'Verifying wireless interface is available...'
    s = cli.execute_shell('ifconfig | grep ' + wlan)
    lines = s.splitlines()
    if stores.args.verbose: print lines

    for line in lines:
        if wlan in line:
            avail = True

    if avail:
        if stores.args.verbose: print 'Interface found.'
        return True
    else:
        if stores.args.verbose:
            print 'Looking a little deeper for that interface you asked for.'
        s2 = cli.execute_shell('ifconfig -a | grep ' + wlan)
        lines = s.splitlines()
        if stores.args.verbose: print lines
        for line in lines:
            if wlan in line:
                if stores.args.verbose:
                    print 'Interface was found...but its not up. You need to fix that...or heck we can...'
        cli.execute_shell('ifconfig ' + wlan + ' up')

        if stores.args.verbose: print 'Interface NOT found anywhere.'
        return False
예제 #4
0
def main(args):
	stores.args = args #stores the args in our structure so any function can retrieve them
	scpath = os.path.realpath(__file__)
	realdir = os.path.dirname(scpath)
	cli.arguments = args #initialize args for cli
	#announce verbose
	if args.verbose: print 'Verbose argument given...prepare to get info...'

	#check deps
	if not check_dependencies():
		print 'Dependency check failed. Please make sure you have all dependencies installed.'
		return

	#check to make sure that the selected interface is valid
	if not ValidInterface():
		print 'The interface you selected is not valid or does not exist.'
		return

	if not stores.args.dumpfile == "": #If a name is specified for the dump file then create it
		if stores.args.verbose: print "Dump file argument given. Creating dump file."
		stores.dumpfilename = stores.args.dumpfile + "/authwatch-dump"
		if not os.path.exists(stores.args.dumpfile):
			if stores.args.verbose: print "Path does not exist trying to create it."
			cli.execute_shell("mkdir -p " + stores.args.dumpfile)
		lout = []
		f = open(stores.dumpfilename,'w') #create an empty file
		f.writelines(lout)
		f.close()
		if stores.args.verbose: print "Dump file with the name " + stores.dumpfilename + " successfully created."

	print "authwatch running..."
	start_sniff()
예제 #5
0
def main(args):
    stores.args = args  #stores the args in our structure so any function can retrieve them
    scpath = os.path.realpath(__file__)
    realdir = os.path.dirname(scpath)
    cli.arguments = args  #initialize args for cli
    #announce verbose
    if args.verbose: print 'Verbose argument given...prepare to get info...'

    #check deps
    if not check_dependencies():
        print 'Dependency check failed. Please make sure you have all dependencies installed.'
        return

    #check to make sure that the selected interface is valid
    if not ValidInterface():
        print 'The interface you selected is not valid or does not exist.'
        return

    if not stores.args.dumpfile == "":  #If a name is specified for the dump file then create it
        if stores.args.verbose:
            print "Dump file argument given. Creating dump file."
        stores.dumpfilename = stores.args.dumpfile + "/authwatch-dump"
        if not os.path.exists(stores.args.dumpfile):
            if stores.args.verbose:
                print "Path does not exist trying to create it."
            cli.execute_shell("mkdir -p " + stores.args.dumpfile)
        lout = []
        f = open(stores.dumpfilename, 'w')  #create an empty file
        f.writelines(lout)
        f.close()
        if stores.args.verbose:
            print "Dump file with the name " + stores.dumpfilename + " successfully created."

    print "authwatch running..."
    start_sniff()
예제 #6
0
  def __init__(self, listenInt, interface, freq, essid, psswd, ip, nm, discoverOnce=True):
    self.robotName = os.getenv('HOSTNAME')
    self.tolerance = 20
    self.x = 0
    self.y = 0
    self.client = WiFiTrilatClient()

    self.discoverOnce = discoverOnce

    rospy.init_node(self.robotName + "_wifitrilat_server")

    #self.rssiPub = rospy.Publisher('/' + self.robotName + '/WiFiRSSI', WiFiRSSIMsg, queue_size=10)
    self.service = rospy.Service("/" + self.robotName + "/WiFiTrilat", WiFiTrilat, self.handle_Trilat)

    self.listenInt = listenInt
    self.interface = interface
    #self.mac = mac.lower()
    self.freq = int(freq)

    self.msgs = []

    cli.execute_shell("ifconfig %s down" % self.listenInt)
    #self.wifi = Wireless(self.interface).setFrequency("%.3f" % (float(self.freq) / 1000))
    self.connectToNet(essid, psswd,ip, nm)
    cli.execute_shell("ifconfig %s up" % self.listenInt)

    self.purge = rospy.Timer(rospy.Duration(2), self.msgPurge)
    self.heartbeat = rospy.Timer(rospy.Duration(1), self.heartbeat_call)
    self.discoverTimer = rospy.Timer(rospy.Duration(20), self.findSelfPos)


    sniff(iface=self.listenInt, prn=self.handler, store=0)
    rospy.spin()
예제 #7
0
def DestoryMonitorInterface():
    if stores.args.verbose:
        print "One moment...getting rid of the monitor interface that we made."
    #Shut down the interface so we can make some changes
    if stores.args.verbose:
        print "Bringing down the " + stores.wlanMonName + " like you asked."
    cli.execute_shell("ifconfig " + stores.wlanMonName + " down")

    #Rename the interface -- ip link set peth0 name eth0
    if stores.args.verbose:
        print "Trying to rename the " + stores.wlanMonName + " to " + str(
            stores.args.interface)
    cli.execute_shell("ip link set " + stores.wlanMonName + " name " +
                      str(stores.args.interface))

    #Change the interface into a monitor interface
    if stores.args.verbose:
        print "Switching the " + str(
            stores.args.interface) + " back to being a managed interface."
    cli.execute_shell("iwconfig " + str(stores.args.interface) +
                      " mode managed")

    #Bring the interface
    #ifconfig <interface> up
    if stores.args.verbose:
        print "Raising the " + str(stores.args.interface) + " like you asked."
    cli.execute_shell("ifconfig " + str(stores.args.interface) + " up")

    return True
예제 #8
0
def CreateMonitorInterface():
    #create the name for our eventual monitor interface
    stores.wlanMonName = str(stores.args.interface) + ".mon"

    #Shut down the interface so we can make some changes
    if stores.args.verbose:
        print "Bringing down the " + str(
            stores.args.interface) + " like you asked."
    cli.execute_shell("ifconfig " + str(stores.args.interface) + " down")

    #Rename the interface -- ip link set peth0 name eth0
    if stores.args.verbose:
        print "Trying to rename the " + str(
            stores.args.interface) + " to " + wlanMonName
    cli.execute_shell("ip link set " + str(stores.args.interface) + " name " +
                      wlanMonName)

    #Change the interface into a monitor interface
    if stores.args.verbose:
        print "Switching the " + wlanMonName + " to being a monitor interface."
    cli.execute_shell("iwconfig " + wlanMonName + " mode monitor")

    #Bring the interface
    #ifconfig <interface> up
    if stores.args.verbose:
        print "Raising the " + wlanMonName + " like you asked."
    cli.execute_shell("ifconfig " + wlanMonName + " up")
    return wlanMonName
예제 #9
0
  def discover(self, event):
    members = [x for x in cli.execute_shell('rostopic list | grep swarmflock/boids').split('\n') if x.find(self.robotName) == -1]

    for x in [x for x in members if x not in self.members and x != '']:
      rospy.loginfo("Discovered member %s" % x)
      self.members.append(x)
      self.boid_subs.append(rospy.Subscriber(x, BoidMsg, self.msg_received))
예제 #10
0
파일: main.py 프로젝트: sececter/hotspotd
def check_interfaces():
	global wlan, ppp
	print 'Verifying interfaces'
	s=cli.execute_shell('ifconfig')
	lines = s.splitlines()
	bwlan = False
	bppp  = False
	
	for line in lines:
		if not line.startswith(' ') and len(line)>0:
			text=line.split(' ')[0]
			if text.startswith(wlan):
				bwlan = True
			elif text.startswith(ppp):
				bppp = True
				
	if not bwlan:
		print wlan + ' interface was not found. Make sure your wifi is on.'
		return False
	elif not bppp:
		print ppp + ' interface was not found. Make sure you are connected to the internet.'
		return False
	else:
		print 'done.'
		return True
예제 #11
0
 def connectToNet(self, essid, psswd, ip, nm):
     rospy.loginfo("Attempting to manually connect...")
     cli.execute_shell("pkill -f wpa_supplicant")
     cli.execute_shell('wpa_passphrase %s \"%s\" > ~/wifitrilat.conf' %
                       (essid, psswd))
     cli.execute_shell("wpa_supplicant -B -i %s -c ~/wifitrilat.conf " %
                       self.interface)
     cli.execute_shell("ifconfig %s %s netmask %s" %
                       (self.interface, ip, nm))
예제 #12
0
  def getNeighbors(self):
    servers = [x for x in cli.execute_shell('rosservice list | grep neighbor_discovery').split('\n') if x != '']
    services = [rospy.ServiceProxy(x, NeighborDiscovery) for x in servers]


    #if len(services) > 1:
    responses = [service(self.suspect) for service in services]
    #else:
    #  responses = services(self.suspect)

    return responses
예제 #13
0
    def __init__(self,
                 listenInt,
                 interface,
                 freq,
                 essid,
                 psswd,
                 ip,
                 nm,
                 discoverOnce=True):
        self.robotName = os.getenv('HOSTNAME')
        self.tolerance = 20
        self.x = 0
        self.y = 0
        self.client = WiFiTrilatClient()

        self.discoverOnce = discoverOnce

        rospy.init_node(self.robotName + "_wifitrilat_server")

        #self.rssiPub = rospy.Publisher('/' + self.robotName + '/WiFiRSSI', WiFiRSSIMsg, queue_size=10)
        self.service = rospy.Service("/" + self.robotName + "/WiFiTrilat",
                                     WiFiTrilat, self.handle_Trilat)

        self.listenInt = listenInt
        self.interface = interface
        #self.mac = mac.lower()
        self.freq = int(freq)

        self.msgs = []

        cli.execute_shell("ifconfig %s down" % self.listenInt)
        #self.wifi = Wireless(self.interface).setFrequency("%.3f" % (float(self.freq) / 1000))
        self.connectToNet(essid, psswd, ip, nm)
        cli.execute_shell("ifconfig %s up" % self.listenInt)

        self.purge = rospy.Timer(rospy.Duration(2), self.msgPurge)
        self.heartbeat = rospy.Timer(rospy.Duration(1), self.heartbeat_call)
        self.discoverTimer = rospy.Timer(rospy.Duration(20), self.findSelfPos)

        sniff(iface=self.listenInt, prn=self.handler, store=0)
        rospy.spin()
예제 #14
0
    def discover(self, event):
        members = [
            x for x in cli.execute_shell(
                'rostopic list | grep swarmflock/boids').split('\n')
            if x.find(self.robotName) == -1
        ]

        for x in [x for x in members if x not in self.members and x != '']:
            rospy.loginfo("Discovered member %s" % x)
            self.members.append(x)
            self.boid_subs.append(
                rospy.Subscriber(x, BoidMsg, self.msg_received))
예제 #15
0
def pre_start():
	try:
		#29-12-2014: Rather than patching individual distros, lets make it a default.
		result = cli.execute_shell('nmcli radio wifi off')
		if "error" in result.lower():
			cli.execute_shell('nmcli nm wifi off')

		cli.execute_shell('rfkill unblock wlan')
		cli.execute_shell('sleep 1')
		print 'done.'
	except:
		pass
예제 #16
0
파일: main.py 프로젝트: sececter/hotspotd
def pre_start():
	try:
		# oper = platform.linux_distribution()
		# if oper[0].lower()=='ubuntu' and oper[2].lower()=='trusty':
			# trusty patch
		# print 'applying hostapd workaround for ubuntu trusty.'
		#29-12-2014: Rather than patching individual distros, lets make it a default.
		result = cli.execute_shell('nmcli radio wifi off')
		if "error" in result.lower():
			cli.execute_shell('nmcli nm wifi off')
		cli.execute_shell('rfkill unblock wlan')
		cli.execute_shell('sleep 1')
		print 'done.'
	except:
		pass
예제 #17
0
def pre_start():
	try:
		oper = platform.linux_distribution()
		if oper[0].lower()=='ubuntu' and oper[2].lower()=='trusty':
			#trusty patch
			print 'applying hostapd workaround for ubuntu trusty.'
			cli.execute_shell('nmcli nm wifi off')
			cli.execute_shell('rfkill unblock wlan')
			cli.execute_shell('sleep 1')
			print 'done.'
	except:
		pass
예제 #18
0
def pre_start():
	try:
		oper = platform.linux_distribution()
		if oper[0].lower()=='ubuntu' and oper[2].lower()=='trusty':
			#trusty patch
			print 'applying hostapd workaround for ubuntu trusty.'
			cli.execute_shell('nmcli nm wifi off')
			cli.execute_shell('rfkill unblock wlan')
			cli.execute_shell('sleep 1')
			print 'done.'
	except:
		pass
예제 #19
0
def stop_router():
	#bring down the interface
	cli.execute_shell('ifconfig mon.' + wlan + ' down')

	#TODO: Find some workaround. killing hostapd brings down the wlan0 interface in ifconfig.
	#~ #stop hostapd
	#~ if cli.is_process_running('hostapd')>0:
		#~ cli.writelog('stopping hostapd')
		#~ cli.execute_shell('pkill hostapd')

	#stop dnsmasq
	if cli.is_process_running('dnsmasq')>0:
		cli.writelog('stopping dnsmasq')
		cli.execute_shell('killall dnsmasq')

	##disable forwarding in iptables.
	#cli.writelog('disabling forward rules in iptables.')
	#cli.execute_shell('iptables -P FORWARD DROP')
	
	#delete iptables rules that were added for wlan traffic.
	if wlan != None:
		cli.execute_shell('iptables -D OUTPUT --out-interface ' + wlan + ' -j ACCEPT')
		cli.execute_shell('iptables -D INPUT --in-interface ' + wlan +  ' -j ACCEPT')

	#cli.execute_shell('iptables --table nat --delete-chain')
	#cli.execute_shell('iptables --table nat -F')
	#cli.execute_shell('iptables --table nat -X')

	##disable forwarding in sysctl.
	#cli.writelog('disabling forward in sysctl.')
	#r = cli.set_sysctl('net.ipv4.ip_forward','0')
	#print r.strip()

	##cli.execute_shell('ifconfig ' + wlan + ' down'  + IP + ' netmask ' + Netmask)
	##cli.execute_shell('ip addr flush ' + wlan)
	print 'hotspot has stopped.'
	return
예제 #20
0
 def discover(self):
     servers = [
         x for x in cli.execute_shell(
             'rosservice list | grep WiFiTrilat').split('\n') if x != ''
     ]
     return servers
예제 #21
0
 def IPtoMAC(self, IP):
     arpCache = cli.execute_shell('arp -n ' + IP)
     mac = re.search(r"(([a-f\d]{1,2}\:){5}[a-f\d]{1,2})",
                     arpCache).groups()[0]
     return mac
예제 #22
0
 def discover(self):
     members = [
         x[1:x.find('/swarmflock')] for x in cli.execute_shell(
             'rostopic list | grep swarmflock/boids').split('\n')
     ]
     return members
예제 #23
0
파일: main.py 프로젝트: sececter/hotspotd
def start_router():
	if not check_dependencies():
		return
	elif not check_interfaces():
		return
	pre_start()
	s = 'ifconfig ' + wlan + ' up ' + IP + ' netmask ' + Netmask
	print 'created interface: mon.' + wlan + ' on IP: ' + IP
	r = cli.execute_shell(s)
	cli.writelog(r)
	#cli.writelog('sleeping for 2 seconds.')
	print 'wait..'
	cli.execute_shell('sleep 2')
	i = IP.rindex('.')
	ipparts=IP[0:i]
	
	#stop dnsmasq if already running.
	if cli.is_process_running('dnsmasq')>0:
		print 'stopping dnsmasq'
		cli.execute_shell('killall dnsmasq')
	
	
	#stop hostapd if already running.
	if cli.is_process_running('hostapd')>0:
		print 'stopping hostapd'
		cli.execute_shell('killall hostapd')
	
	#enable forwarding in sysctl.
	print 'enabling forward in sysctl.'
	r=cli.set_sysctl('net.ipv4.ip_forward','1')
	print r.strip()
	
	#enable forwarding in iptables.
	print 'creating NAT using iptables: ' + wlan + '<->' + ppp
	cli.execute_shell('iptables -P FORWARD ACCEPT')
	
	#add iptables rules to create the NAT.
	cli.execute_shell('iptables --table nat --delete-chain')
	cli.execute_shell('iptables --table nat -F')
	r=cli.execute_shell('iptables --table nat -X')
	if len(r.strip())>0: print r.strip()
	cli.execute_shell('iptables -t nat -A POSTROUTING -o ' + ppp +  ' -j MASQUERADE')
	cli.execute_shell('iptables -A FORWARD -i ' + ppp + ' -o ' + wlan + ' -j ACCEPT -m state --state RELATED,ESTABLISHED')
	cli.execute_shell('iptables -A FORWARD -i ' + wlan + ' -o ' + ppp + ' -j ACCEPT')
	
	#allow traffic to/from wlan
	cli.execute_shell('iptables -A OUTPUT --out-interface ' + wlan + ' -j ACCEPT')
	cli.execute_shell('iptables -A INPUT --in-interface ' + wlan +  ' -j ACCEPT')

	
	#start dnsmasq
	s = 'dnsmasq --dhcp-authoritative --interface=' + wlan + ' --dhcp-range=' + ipparts + '.20,' + ipparts +'.100,' + Netmask + ',4h'
	print 'running dnsmasq'
	r = cli.execute_shell(s)
	cli.writelog(r)
	
	#~ f = open(os.getcwd() + '/hostapd.tem','r')
	#~ lout=[]
	#~ for line in f.readlines():
		#~ lout.append(line.replace('<SSID>',SSID).replace('<PASS>',password))
		#~ 
	#~ f.close()
	#~ f = open(os.getcwd() + '/hostapd.conf','w')
	#~ f.writelines(lout)
	#~ f.close()
	
	#writelog('created: ' + os.getcwd() + '/hostapd.conf')
	#start hostapd
	#s = 'hostapd -B ' + os.path.abspath('run.conf')
	s = 'hostapd -B ' + os.getcwd() + '/run.conf'
	cli.writelog('running hostapd')
	#cli.writelog('sleeping for 2 seconds.')
	cli.writelog('wait..')	
	cli.execute_shell('sleep 2')
	r = cli.execute_shell(s)
	cli.writelog(r)
	print 'hotspot is running.'
	return	
예제 #24
0
파일: main.py 프로젝트: sececter/hotspotd
def configure():
	global wlan, ppp, IP, Netmask
	#CHECK WHETHER WIFI IS SUPPORTED OR NOT
	print 'Verifying connections'
	wlan=''
	ppp=''
	s=cli.execute_shell('iwconfig')
	if s!=None:
		lines = s.splitlines()
		#print 'and it is:'  + s
		for line in lines:
			if not line.startswith(' ') and not line.startswith('mon.') and 'IEEE 802.11' in line:
				wlan=line.split(' ')[0]
				print 'Wifi interface found: ' + wlan
			
	if wlan=='':
		print 'Wireless interface could not be found on your device.'
		return
			
	#print 'Verifying Internet connections'
	s=cli.execute_shell('ifconfig')
	lines = s.splitlines()
	iface=[]
	for line in lines:
		if not line.startswith(' ') and not line.startswith(wlan) and not line.startswith('lo') and not line.startswith('mon.') and len(line)>0:
			iface.append(line.split(' ')[0])
			#print 'f::' + line
			
	if len(iface)==0:
		print 'No network nic could be found on your deivce to interface with the LAN'
	elif len(iface)==1:
		ppp=iface[0]
		print 'Network interface found: ' + ppp
	else:
		rniface=range(len(iface))
		s=''
		while True:
			for i in rniface:
				print i, iface[i]
			try: s = int(input("Enter number for internet supplying NIC :"))
			except: continue
			if s not in rniface:
				continue
			ppp=iface[s]
			break
	
	while True:
		IP= raw_input('Enter an IP address for your ap [192.168.45.1] :')
		#except: continue
		#print type(IP)
		#sys.exit(0)
		if IP==None or IP=='':
			IP='192.168.45.1'
		if not validate_ip(IP): continue
		break
		
	Netmask='255.255.255.0'
	
	#CONFIGURE SSID, PASSWORD, ETC.
	SSID=raw_input('Enter SSID [joe_ssid] :')
	if SSID=='': SSID='joe_ssid'
	password=raw_input('Enter 10 digit password [1234567890] :')
	if password=='': password='******'
	
	f = open('run.dat','r')
	lout=[]
	for line in f.readlines():
		lout.append(line.replace('<SSID>',SSID).replace('<PASS>',password))
		
	f.close()
	f = open('run.conf','w')
	f.writelines(lout)
	f.close()
	
	print 'created hostapd configuration: run.conf'
	
	dc = {'wlan': wlan, 'inet':ppp, 'ip':IP, 'netmask':Netmask, 'SSID':SSID, 'password':password}
	json.dump(dc, open('hotspotd.json','wb'))
	print dc
	print 'Configuration saved'
예제 #25
0
 def connectToNet(self, essid, psswd, ip, nm):
   rospy.loginfo("Attempting to manually connect...")
   cli.execute_shell("pkill -f wpa_supplicant")
   cli.execute_shell('wpa_passphrase %s \"%s\" > ~/wifitrilat.conf' % (essid, psswd))
   cli.execute_shell("wpa_supplicant -B -i %s -c ~/wifitrilat.conf " % self.interface)
   cli.execute_shell("ifconfig %s %s netmask %s" % (self.interface, ip, nm))