logo
down
shadow

Python KeyError scanning list of hosts for open ports


Python KeyError scanning list of hosts for open ports

By : user2950128
Date : November 17 2020, 11:52 AM
I wish this help you I have a list of my ip's in my python script, and I'm trying to run a nmap scan on each of them to find open ports. I keep getting this error: , Like this, based on your code:
code :
for item in L:
    if item in nm.all_hosts():
        for port in nm[item].all_tcp():
            state = nm[item]['tcp'][port]['state']
            if state == 'open':
                print state
items = list(set(L) & set(nm.all_hosts()))

for item in items:
    for port in nm[item].all_tcp():
        state = nm[item]['tcp'][port]['state']
        if state == 'open':
            print state


Share : facebook icon twitter icon
Instead of scanning multiple ports I'm scanning only one and when port is closed my app closes

Instead of scanning multiple ports I'm scanning only one and when port is closed my app closes


By : phani kumar vadlaman
Date : March 29 2020, 07:55 AM
Any of those help In your callback method, I would make sure close the connection and dispose of the TcpClient. Also TcpClient.EndConnect(IAsyncResult) can also throw exceptions. I also do not see where capturing the port number for display to the user. I would write the callback something like this.
Edit: I didn't actually compile or execute my code (sorry). I also found this other article that shows how to create a port scanner in C#, http://www.dijksterhuis.org/building-a-simple-portscanner-in-c/ There is a comment in this post stating,
code :
private void CallBack(IAsyncResult result) 
{ 
    var client = (TcpClient)result.AsyncState; 
    bool connected = false;

    try
    {
        client.EndConnect(result);
        connected = client.Connected;
    }
    catch (SocketException)
    {
    }
    catch (ObjectDisposedException)
    {
    }
    finally
    {
        if (client.Connected)
        {
            client.Close();
        }

        client.Dispose();
    }

    if (connected) 
    { 
        this.Invoke((MethodInvoker)delegate 
        { 
            txtDisplay.Text += "open2" + Environment.NewLine; 
        }); 
    } 
    else 
    { 
        this.Invoke((MethodInvoker)delegate 
        { 
            txtDisplay.Text += "closed2" + Environment.NewLine; 
        }); 
    } 
} 
Scanning ports on non local hosts

Scanning ports on non local hosts


By : struzzo
Date : March 29 2020, 07:55 AM
around this issue try to set a timeout on a socket. It will fail faster.
connection.setSoTimeout(10*1000); // milliseconds
How do I connect external ports on applications running on different hosts using python?

How do I connect external ports on applications running on different hosts using python?


By : Анна Васьковська
Date : March 29 2020, 07:55 AM
To fix the issue you can do I'm going to use docker to emulate your environment. Hopefully I understood your situation correctly. I have 3 machines. A, B, and C. A and B each have their own domain, GPP, and running waveform. In my case A and B are docker containers. C will be used to reach out and interact with A and B making the connections.
These images are public so feel free to follow along if you have docker installed.
code :
# Launch our 2.0.2 container
[ylb@axios]$docker run -it --rm axios/redhawk:2.0.2 bash -l

# Install a test waveform
[redhawk@6b0701e76e74 ~]$ sudo yum install -y rh.FM_mono_demo

# Start the omni services
[redhawk@6b0701e76e74 ~]$ sudo $OSSIEHOME/bin/cleanomni

# Start domain and dev manager
[redhawk@6b0701e76e74 ~]$ nodeBooter --daemon -D
[redhawk@6b0701e76e74 ~]$ nodeBooter --daemon -d $SDRROOT/dev/nodes/DevMgr_12ef887a9000/DeviceManager.dcd.xml

# Launch the waveform via python
[redhawk@6b0701e76e74 ~]$ python
>>> from ossie.utils import redhawk
>>> dom = redhawk.attach()
>>> app = dom.createApplication('/waveforms/rh/FM_mono_demo/FM_mono_demo.sad.xml')
[ylb@axios]$python
>>> from ossie.utils import redhawk
>>> dom1 = redhawk.attach('REDHAWK_DEV', '172.17.0.3')
>>> dom2 = redhawk.attach('REDHAWK_DEV', '172.17.0.2')
>>> app1 = dom1.apps[0]
>>> app2 = dom2.apps[0]
>>> app1.comps[0].name
'rh.TuneFilterDecimate'
>>> tfd1 = app1.comps[0]
>>> app2.comps[1].name
'rh.psd'
>>> psd2 = app2.comps[1]
>>> tfd1.connect(psd2)
how to exclude Hosts from IP range from scanning inside nmap python script

how to exclude Hosts from IP range from scanning inside nmap python script


By : Kirsh K
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further would appreciate your advice how to exclude hosts from scanning inside the nm.scan().I have the following script which works perfectly when i enter the range : for example 10.0.0.0/24 , I got it.Needed to put the arguments first:
code :
nm.scan(arguments='-sT --open --exclude X.X.X.X,X.X.X.X',hosts='X.X.X.0/24')
Why is my Port Scanner not scanning ports in Python?

Why is my Port Scanner not scanning ports in Python?


By : Uci Arahito Lubis
Date : March 29 2020, 07:55 AM
seems to work fine Found the solution. The problem that I was facing was, that the IP-adress was using a list function in which I needed it to convert it to a string in order to use s.connect_ex
code :
#!usr/bin/env python
import subprocess
import ipaddress
from socket import *


# Value to scan the network 192.168.2.0 till 192.68.2.14
net_addr = '192.168.2.0/28'

# Variables for the port numbers
portstart = 79
portend =  140

# Resolve hostname
host = gethostname()

# Creates the network
ip_net = ipaddress.ip_network(net_addr)

# Get all hosts in the network
all_hosts = list(ip_net.hosts())

# Configure subprocess to hide the console window
info = subprocess.STARTUPINFO()
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = subprocess.SW_HIDE

# Loop where the IP-address is being pinged.
for i in range(len(all_hosts)):
    output = subprocess.Popen(['ping', '-n', '1', '-w', '500', str(all_hosts[i])], stdout=subprocess.PIPE,
                              startupinfo=info).communicate()[0]

    if "Destination host unreachable" in output.decode('utf-8'):
        print(str(all_hosts[i]), "is Offline")

    elif "Request timed out" in output.decode('utf-8'):
        print(str(all_hosts[i]), "is Offline")

    else:
        print(str(all_hosts[i]), "is ONLINE!")
        print ("The hostname of", all_hosts[i], "is:", host)
        print ("Starting scan on host: ", host, "(", all_hosts[i], ")")

# Loop where it scans ports within a range.
        for portnum in range (portstart, portend):
                s = socket(AF_INET, SOCK_STREAM)

                result = s.connect_ex((str(all_hosts[i]), portnum))

                if (result == 0):
                    print ("Port", portnum, "is OPEN!")
                    s.close()

                else:
                    print("Port", portnum, "is closed")
Related Posts Related Posts :
  • Return new instance of subclass when using methods inherited from parent class in Python
  • Which function in django.contrib.auth creates the default model permissions?
  • Formatting text in tabular form with Python
  • How to determine the first day of a month in Python
  • Error while converting date to timestamp in python
  • Python string iterations
  • Is there any file number limitation when you select multiple files with wxFileDialog?
  • Errors with Matplotlib when making an executable with Py2exe (Python)
  • Django Haystack - Indexing single field
  • Go Pro Hero 3 - Streaming video over wifi
  • Appending a column in .csv with Python/Pandas
  • How to change my result directory in Robot framework using RIDE?
  • problem with using pandas to manipulate a big text file in python
  • python-magic module' object has no attribute 'open'
  • Where goes wrong for this High Pass Filter in Python?
  • Why inserting keys in order into a python dict is faster than doint it unordered
  • flann index saving in python
  • Create new instance of list or dictionary without class
  • How can I easily convert FORTRAN code to Python code (real code, not wrappers)
  • Address of lambda function in python
  • Python adding space between characters in string. Most efficient way
  • python http server, multiple simultaneous requests
  • Disguising username & password on distributed python scripts
  • Post GraphQL mutation with Python Requests
  • Why doesnt pandas create an excel file?
  • Rolling comparison between a value and a past window, with percentile/quantile
  • How to avoid repetitive code when defining a new type in python with signature verification
  • How to configure uWSGI in order to debug with pdb (--honour-stdin configuration issue)
  • In Python, how do you execute objects that are functions from a list?
  • Python- Variable Won't Subtract?
  • Processing Power In Python
  • Python 2.7.2 - Cannot import name _random or random from sys
  • Why doesn't the Python sorted function take keyword order instead of reverse?
  • Make a function redirect to other functions depending on a variable
  • get_absolute_url in django-categories
  • Monitoring non-Celery background task with New Relic in Python
  • Feature selection with LinearSVC
  • LSTM - Predicting the same constant values after a while
  • Test the length of elements in a list
  • Django: render radiobutton with 3 columns, cost column must change according to size & quantity selected
  • Python class attributes vs global variable
  • sys.stdout.writelines("hello") and sys.stdout.write("hello")
  • is ndarray faster than recarray access?
  • Python - search through directory trees, rename certain files
  • GAE: How to build a query where a string begins with a value
  • TypeError: __init__() takes at least 2 arguments (1 given)
  • Overriding and customizing "django.contrib.auth.views.login"
  • Django : Redirect to a particular page after login
  • Python search and copy files in directory
  • pretty printing numpy ndarrays using unicode characters
  • Frequent pattern mining in Python
  • How can I make a set of functions that can be used synchronously as well as asynchronously?
  • Convert one dice roll to two dice roll
  • count occourrence in a list
  • Writing an If condition to filter out the first word
  • to read file and compare column in python
  • Install python-numpy in the Virtualenv environment
  • `.select_by_visible_text()` is failed to select element?
  • Unable to send data multiple requests in a single connection — socket error
  • Pandas HDFStore unload dataframe from memory
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org