54
54
print 'Please look for "ndiswrapper" in your distribution\'s package manager and install it or go to www.ndiswrapper.com and download the latest sources'
57
if (opts.debug): ##Print the debug options enabled
57
##Print the debug options enabled
58
59
print '[DEBUG] Options:'
60
61
print '[DEBUG] Arguments:'
64
def get_and_print_card_info():
65
##The function's name is self explanatory, but aniway this is thanks to mintwifi.py
66
os.system('lspci | grep \"Network controller\" > /tmp/detected_wireless_devices')
67
devices_file = open('/tmp/detected_wireless_devices')
68
for device_item in devices_file.readlines():
69
devicearray = device_item.split()
70
device = ' '.join(devicearray[3:])
71
pci_id_line = commands.getoutput('lspci -n | grep ' + devicearray[0])
72
pci_id_array = pci_id_line.split()
73
pci_id = ' '.join(pci_id_array[2:])
67
Like commands.getoutput, but uses subprocess.
70
myproc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
71
value = myproc.stdout.read()
74
def get_output_retcode(*cmd):
76
myproc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
77
value = myproc.stdout.read()
78
retcode = myproc.wait()
81
def get_print_card_info():
83
Prints the pci id and other information about the pci wireless cards.
85
output = getoutput('lspci')
74
89
print ' -- ' + device
75
90
print ' ==> PCI ID = ' + pci_id
78
93
def check_for_internet(url, card_id):
79
##Checks if the user has an internet connection available
95
Pings google to see if the user has an internet conecction available.
80
98
print '[*] Looking if an Internet connection is available, this may take a few seconds.'
81
test = commands.getoutput('ping -c 1 google.com')
99
test = getoutput('ping', '-c', '1', 'google.com')
82
100
if 'unknown host' in test:
83
101
print '[ERROR] An Internet connection was not found'
84
102
choice = raw_input('(C)ontinue, (R)etry, (O)ffline mode or (E)xit: ')
103
121
print '[*] Internet connection found, continuing installation'
106
def searchcard(card_id, database):
107
##Looks if card is in the list of supported cards
124
def searchcard(devices_list, database):
126
Looks if one of the ids in the devices list given as argument matches an entry in the database given as argument.
129
for item in devices_list:
110
130
if item in database:
115
for element in iterable:
120
134
def remove_old_drivers():
121
##Removes existing wireless drivers
136
Removes existing wireless drivers.
122
139
print '[*] Removing Old Drivers:'
123
140
baddrivers = yourcard_dic['blacklist']
124
if baddrivers in commands.getoutput('lsmod| awk "{print $1}"'):
141
if baddrivers in getoutput('lsmod| awk "{print $1}"'):
125
142
print ' removing %s' % (baddrivers, )
126
os.system('rmmod %s' % (baddrivers, ))
143
subprocess.call(['rmmod', baddrivers])
128
145
print ' drivers not loaded, nothing to remove'
130
147
def blacklist_drivers():
131
##Blacklists existing wireless drivers
149
Blacklists existing wireless drivers.
132
152
print '[*] Blacklisting:'
133
153
baddrivers = yourcard_dic['blacklist']
134
154
if any(baddrivers in line.split('#')[0] for line in open('/etc/modprobe.d/blacklist')):
199
228
return decompression
201
230
def fetch(url, card_id):
202
##Determine decompression method
232
Downloads the apropiate driver.
203
235
print '[*] Downloading driver now from "%s"' % (url, )
205
237
retcode = subprocess.call(['wget', url, '-qO', opts.tmp_dir/card_id/driver])
207
print '[ERROR] Download unsuccessfull, please check your Internet conecction'
239
print '[ERROR] Download unsuccessfull, please check your Internet conecction'
210
242
retcode = subprocess.call(['wget', url, '-O', opts.tmp_dir/card_id/driver])
212
print '[ERROR] Download unsuccessfull, please check your Internet conecction'
244
print '[ERROR] Download unsuccessfull, please check your Internet conecction'
214
246
print ' Download successfull'
216
248
def extract(decompression):
250
Extracts the dowloaded driver.
217
253
print '[*] Extracting driver'
244
280
return extract(decompression)
246
manualmode(url, card_id)
248
282
def manualmode(url, card_id):
249
##Comes into play if the user doesn't have an internet connection or if the driver need to be fetched manually
284
Comes into play if the user doesn't have an internet connection or if the driver need to be fetched manually.
250
286
yourcard_dic = data[card_id]
251
287
driver = yourcard_dic['driver']
252
288
print 'The driver needs to be fetched manually from: %s' % (url, )
253
289
print 'Please place the "%s" file, along with the .sys files into:' % (driver, )
254
print '"%s/%s/"' % (opts.tmp_dir, card_id, )
290
print '"%s/%s"' % (opts.tmp_dir, card_id, )
255
291
while not any(driver in line for line in os.listdir('%s/%s/' % (opts.tmp_dir, card_id, ))):
256
#while ((commands.getoutput("ls %s/%s/|grep %s" % (opts.tmp_dir, card_id, driver, ))) == ""):
258
294
dummy = raw_input('When you have succesfully dowloaded the driver and extracted it press <Enter>: ')
261
##Executed when CTRL + C is pressed
297
##Executed when CTRL + C is pressed.
262
298
print '\n\nCanceled!\n'
264
300
print ' Driver file found! Continuing installation.'
266
302
def installdriver(card_id):
267
##Installs the driver with NDISwrapper
304
Installs the driver with NDISwrapper.
268
307
driver = yourcard_dic['driver']
269
Inf = commands.getoutput('find %s/%s/ -name %s' % (opts.tmp_dir, card_id, driver, ))
308
inf_file = getoutput('find', opts.tmp_dir/card_id, '-name', driver)
270
309
if ( opts.debug ):
271
print '[DEBUG] Driver found at %s' % (Inf, )
272
os.system('%s -i %s' % (opts.ndiswrapper_bin, Inf, ))
273
os.system('%s -l' % (opts.ndiswrapper_bin, ))
274
os.system('%s -ma' % (opts.ndiswrapper_bin, ))
275
os.system('modprobe ndiswrapper')
276
os.system('echo ndiswrapper >> /etc/modules')
310
print '[DEBUG] Driver found at %s' % (inf, )
312
#Attempt to install driver.
313
output, retcode = get_output_retcode('ndiswrapper', '-i', inf_file)
315
#Attempt to detect errors.
316
if "already" in output:
317
print 'Driver is already installed!'
278
print 'Installation finished'
321
print '[ERROR] Driver installation failed'
325
##Assume driver installed successfully. Set up and reload module.
326
subprocess.call(['ndiswrapper', '-ma'])
327
subprocess.call(['modprobe', '-r', 'ndiswrapper'])
328
subprocess.call(['modprobe', 'ndiswrapper'])
329
print 'Installation finished'
281
332
def create_log_file():
334
Creates a simple log file with some useful info.
282
337
log = open('auto-ndis-log.txt', 'w')
284
339
os_info = os.uname()
285
340
distribution = platform.dist()
286
ndis_version = commands.getoutput('ndiswrapper -v')
341
ndis_version = getoutput('ndiswrapper', '-v')
288
343
log.write('OS and date = ')
289
344
for item in os_info:
306
361
def get_card_id():
307
362
##Gets the id of all the pci devices
308
outtext = commands.getoutput('lspci -n')
363
outtext = getoutput('lspci', '-n')
309
365
##Stores the pci ids with the revision number in a list
310
366
pci = re.findall('.{4}:.{4}\ \(rev .{2}\)',outtext)
312
368
##Gets the id of all the usb devices
313
outtext2 = commands.getoutput('lsusb')
369
outtext2 = getoutput('lsusb')
314
370
##Stores the usb ids in a list
315
371
usb = re.findall('.{4}:.{4}',outtext2)
319
373
pcicard = searchcard(pci, data)
320
374
usbcard = searchcard(usb, data)
330
384
elif pcicard != -1 and usbcard != -1:
331
choice = input('Setup (w)ificard or setup your (u)sbcard?: ')
385
choice = raw_input('Setup (w)ificard or setup your (u)sbcard?: ')
333
while choice != 'w' and choice != 'W' and choice != 'u' and choice != 'U':
387
while choice != 'W' and choice != 'w' and choice != 'U' and choice != 'u':
334
388
print 'Please try again'
335
choice = input('Setup (w)ificard or setup your (u)sbcard?: ')
336
if choice == 'w' or chice == 'W':
389
choice = raw_input('Setup (w)ificard or setup your (u)sbcard?: ')
390
if choice == 'W' or choice == 'w':
392
elif choice == 'U' or choice == 'u':
341
397
elif pcicard == -1 and usbcard == -1:
342
398
print 'Sorry, card not yet supported by Auto-NDISwrapper'
343
399
print 'Save this output as it will help other people give you support'
344
get_and_print_card_info()
400
get_print_card_info()
347
403
card_id = get_card_id()