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

  • SEARCH
  • Home
  • 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 8298203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:41:07+00:00 2026-06-08T15:41:07+00:00

I am using nmap in python, and trying to scan the network using a

  • 0

I am using nmap in python, and trying to scan the network using a text file. All the scan ranges are in a text file, like so:

192.168.1.1-100
192.168.1.120-200
…

Though, lets say if the scan did not find host 192.168.1.3, because it was offline. The program will crash. Is there a way that I can get around this crashing? Can I use something like Try / Catch?


counter = 0
with open('range.txt') as rangefile:
    content = rangefile.readlines()

while counter < len(content):
    nm = nmap.PortScanner()
    #define the nmap scan here
    nm.scan(content[counter], '517', '-sU -sT')

This is the sample of code

  File "c:\...\nmapscan.py", line 63, in <module> therehost = Host.objects.get(ipv4_address=hosts) va.assessment.models.DoesNotExist: Host matching query does not exist. Lookup parameters were {'ipv4_address': u'134.250.16.103'}

This is the error

  • 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-06-08T15:41:08+00:00Added an answer on June 8, 2026 at 3:41 pm

    nmap takes two arguments for exclusion. --exclude takes host name(s) and --excludefile takes a file containing name of hosts that need to be excluded. Use one of these as your need.
    For more on setting target see the man page.

    Here is my test result –

    Python 3.2.3 (default, May  3 2012, 15:54:42) 
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import nmap
    >>> nm=nmap.PortScanner()
    >>> nm.scan('134.250.16.103','517', '-sU -sT')
    {'nmap': {'scanstats': {'uphosts': '0', 'timestr': 'Sat Jul 28 12:54:27 2012', 'downhosts': '1', 'totalhosts': '1', 'elapsed': '3.06'}, 'scaninfo': {'udp': {'services': '517', 'method': 'udp'}, 'tcp': {'services': '517', 'method': 'connect'}}, 'command_line': 'nmap -oX - -p 517 -sU -sT 134.250.16.103'}, 'scan': {'134.250.16.103': {'status': {'state': 'down', 'reason': 'no-response'}, 'hostname': ''}}}
    >>> 
    

    You can use try-catch-

    try:
       nm.scan(content[counter], '517', '-sU -sT')
    except:
       #handle exception...
    

    As you don’t which servers are down, you can ping the server before you proceed to nmap scan.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Ruby to run an nmap -sP ping scan on my home network
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using the Redis info command, I am able to get all the stats of
Using import datetime in python, is it possible to take a formatted time/date string
Using ASIHTTPRequest, I downloaded a zip file containing a folder with several audio files.
I use vim under iterm2. I'm using the NERDCommenter plugin, and I'd like to
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
Using Rails 3.2.0 with haml and sass: I Would like to link an external
I've found a strange behaviour in Nmap (I am using version 5.51 if that
I have hierarchical data stored in the datastore using a model which looks like

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.