last day (15 days later) » 

9:33 PM
1
A: Python3.4 -Nmap Requires root privileges

DuplexiaRunning IDLE as root might work, but it might not be a great idea. sudo idle Option 1 (recommended): Put the code requiring elevated privileges in a python file which you run with sudo. I assume you want to play with the results, so you could have the script save the results to a file, which ...

 
bob
can you elaborate on how you do option one? I am not sure what you mean by that and how to do it
 
Updated the answer with some code on how you might do option 1
 
bob
Note, I do not want to have to run it on the terminal.. I would like to do be able to run it on the IDLE if possible
 
Your only option is to run IDLE as root then. sudo idle in terminal. It's a bad security practice though so do so at your own risk.
 
bob
Why is it a risk, if I only scan with nmap, there shouldn't be any risks right? And so I would have to run the option 2: Place that code before my code and run it? (tho I understand what it does...)
 
9:33 PM
If you run idle as root you could do everything in idle without option 1 or 2 (just do what you were doing before). It's a bad security practice because all of the code you write has root privileges. Be careful what you put in there. You can find a lot more information about why running arbitrary code as root is a bad practice on the web. There's no problem with running the given code as root- but all other code you write will also be executed as root, which is where the problem lies.
 
bob
I will accept your answer in a sec, is it normal that in the terminal I cannot run : sudo python myfile.py ... I have to go to the directory first with : cd mylocation?
 
what's the error?
this is really a separate question because you don't need to run that file as root anymore if you're running idle as root
 
bob
It is wierd.. here is all my code I guess with option 2
from subprocess import Popen, PIPE
cmd = ['sudo', '-S', 'python', 'nmaproot.py']
sudopass = 'mypassword'
p = Popen(cmd, stdin=PIPE, stderr=PIPE,universal_newlines=True, stdout=PIPE)
output = p.communicate(sudopass + '\n')
import nmap
import json

nm = nmap.PortScanner()
nm.scan('192.168.5.1/24',arguments='-O') #Note that I tested with -sP to save time
output = []
with open('output.txt', 'a') as outfile:
for h in nm.all_hosts():
if 'mac' in nm[h]['addresses']:
item = nm[h]['addresses']
if nm[h]['vendor'].values():
item['vendor'] = list(nm[h]['vendor'].values())[0]
output.append(item)
json.dump(output, outfile)
--------------- so this would be my code right?
 
i really wouldn't mess with option 2. you're making your life difficult
i wanted to see if it could be done and by the time i finished i realized it was stupid
 
bob
Well actually I already have problems with it lol
I wont use it... but can't use terminal anymore
 
9:39 PM
why are you averse to running a terminal command?
 
bob
[forkpty: Resource temporarily unavailable]
[Could not create a new process and open a pseudo-tty.]
 
i only tested option 2 on python2.7, that could be the issue
 
bob
on mac, when I want to run a script I was used to press f5 which was easy. I was sure there was a way to fix the problem with nmap (I cannot believe I am the only one with this problem(
 
it's a bad option so i never tested for compatibility and don't recommend pursuing it
 
bob
do you place the script to a specific location before running your command in the terminal?
because I hve to cd first
to where my file is located
 
9:42 PM
no i could do it from wherever. what's the error?
 
bob
well atm I cannot use the terminal xD
ill reboot... brb
are you on OS X ?
 
o.0
yes..why can't you use the terminal
 
bob
I cannot shutdown my mac
my terminal wont close
force reboot (got it)
when running: sudo python okok.py
python: can't open file 'okok.py': [Errno 2] No such file or directory
 
uhh
you have to provide the folder of course
sudo python myfolder/okok.py
the full relative path from your terminal location or the absolute path
I suggest you get comfortable with the terminal, you can't live with just an interactive python console forever
 
bob
9:58 PM
Yea, for this project I will have to deal with it
 
you're not allowed to use the terminal or something?
 
bob
terminal, I am confortable but I was just wondering because it seemed to be different for you
 
the terminal is your friend, not your enemy :)
 
bob
I force rebooted now it works fine
 
okay, great
good luck!
 
bob
9:59 PM
hey wait
 
?
 
bob
it is not related with the question (and we could discuss this somewhere else) but do you work with nmap?
 
not frequently no
 
bob
Alright well I thank you very much for your time!!
 
i generally have to search the web every time i want to run something
sure thing
 
bob
10:01 PM
I hope you have a great day =)
 

last day (15 days later) »