Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6343489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:26:52+00:00 2026-05-24T20:26:52+00:00

So I am running code that looks like this on Ubuntu 11.4 and Python

  • 0

So I am running code that looks like this on Ubuntu 11.4 and Python 2.7:

p_scan_command = "sudo nmap -sC -sV -PN -O 192.168.0.1/24"
time.sleep(1.5)
os.system(p_scan_command)
f = open('nmapscan1.log', 'r')
print f.read()
f.close()

What is happening is that I end up with no results, and the scan is not being run, probably because it is being run with ‘sudo’. I want to know

  1. If I have been correct in my diagnosis of the problem and
  2. How to fix it?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:26:52+00:00Added an answer on May 24, 2026 at 8:26 pm
    1. Are you sure that the log file is even created? I cannot see where this name is mentionned – but maybe it is created by default.

    2. Are you asked for the password by sudo?
      This could tell you if sudo is really run.

    3. os.system is kind of deprecated or at least frowned upon; better use subprocess.call(), subprocess.check_call() or subprocess.Popen() (gives you an object which you can use to further control the process).


    EDIT: Just tested. Here the scan runs, but the output gets displayed instead of written to a file. Probably you are missing the > nmapscan1.log part in the os.system() call.

    With subprocess, you would write

    sp = subprocess.Popen(['sudo', 'nmap', '-sC', '-sV', '-PN', '-O', '192.168.0.1/24'],
        stdout=file("nmapscan1.log", "w"))
    sp.wait()
    f = open('nmapscan1.log', 'r')
    print f.read()
    f.close()
    

    or if you don’t need the file, simply

    sp = subprocess.Popen(['sudo', 'nmap', '-sC', '-sV', '-PN', '-O', '192.168.0.1/24'],
        stdout=subprocess.PIPE)
    print sp.stdout.read()
    sp.wait()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running a bit of code that looks like this: result = system(ruby
I am using python 2.7, I have some code that looks like this: task1()
I've got some UI code that looks like this: try { SomeClass classInstance =
Let's say I have a line of code that looks like this: setInterval(ajaxFunction,3000); where
I've got some code that looks like this: <div id=shell> <div id=title>TITLE HERE</div> <div
I'm running a scheduling algorithm with a garbage collection snippet that looks like this:
In my code I have a query that looks like this: $load_query = LOAD
I have a piece of code that looks like this: downloadsByExtensionCount = defaultdict(int) downloadsByExtensionList
I have written some code that looks more or less like this: QVector<QRgb> colorTable(256);
I have some code that looks like the below. Does this create a deadlock?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.