Viewing and managing socket usage in Python [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to create a utility using Python (3) that, among other things, needs to look at and manage socket usage ON WINDOWS (no, I really don't care if it works on other OS's).
Looking at socket usage: To be clear, I don't want to create a socket or bind to an existing one, I want to be able to get a full list of what sockets are open and what programs have opened them. If you're not sure about what I mean, take a look at TCPView, which does exactly what I'm talking about.
Managing socket usage: Basically, I want to be able to stop programs from connecting from the internet, if necessary. I would assume that the easiest way to do this is to use os.system() to add a new rule to the Windows Firewall, but as that doesn't seem too elegant I'm open to suggestions.
As that's obviously not all the utility will do, I would prefer a library/module of some sort over a 3rd-party program.

You can launch the command "netstat -nabo" to get the list of all active connections & parse the output to get the source, destination, process name & ID. There is no straight forward method to get the active connections in python. You can also get the same information from python invoking iphlpapi. To block or allow a connection windows has command line to add/remove rule from windows firewall.

Related

Could you check it's possible (Selenium python automation + PHP) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Our system is developed with PHP and one of our coworkers developed Amazon automation program with Python.
I am wondering if it's possible to integrate together ?
if it is please recommend what ways i can do this
https://github.com/jasonminsookim/order_automation/blob/master/src/amzn.py
Here's code Amazon automation program
Thank you
There are lots of ways to do this, but I would weigh what you have available to you and go from there. The tempfile solution is the most general, and is a common interface pattern for any two or more languages, but you can get more exotic if performance is a major concern with pipes.
Temp-file
I guess the most rudimentary way to do this would be to have the python file output some data to a file that can be read in by php or vice versa.
Something like creating a directory called /orders where php put's in order.json files and python takes those in, reads them and gets the result, then puts it back as a order-result.json. Essentially a temp-file system to communicate between the two.
Pipes
Alternatively depending on your setup you could pipe results into php from python with something like the subprocessing module and a php CLI that interfaces with your DB.

How to use Python to Interface with z/OS Services to Automate Manual Processes [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to automate some manual process on Mainframe, for that I want to use Python. I'm aware of some interfaces using FTP via ftplib. My immediate task is to
Query existing job status/ log in spool...
Any documentation or help is appreciated.
Have you considered using the z/OSMF jobs REST APIs?
https://www.ibm.com/support/knowledgecenter/SSLTBW_2.4.0/com.ibm.zos.v2r4.izua700/IZUHPINFO_API_RESTJOBS.htm
You can use python to issue REST calls to get what you need.
Since you're interested in using python, you should also be aware of the Z Open Automation Utilities (no charge!)
This is a set of utilities that help manage mvs through shell commands in Unix System Services, Java, python, Ansible...
Here is an introductory link - be sure to use the side-bar on the left and expand the code examples, there are examples using the utilities on datasets and jobs.
https://www.ibm.com/support/knowledgecenter/SSKFYE_1.0.2/zoautil_purpose.html

how to transfer session to another compute node with python? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 days ago.
Improve this question
How to transfer session to another compute node with python in the following case?
case 1: If using kubernete,
case 2: Or using autoscale,
case 3: if using Amazon,
How to transfer session to another compute node with python?
So that program can run forever
Nope, none of those things can transfer a process with all of its in-memory and on-disk state across hosts.
If you’re looking at Kubernetes already, I’d encourage you to design your application so that it doesn’t have any local state. Everything it knows about lives in a database that’s maintained separately (if you’re into AWS, it could be an RDS hosted database or something else). Then you can easily run multiple copies of it (maybe multiple replicas in a Kubernetes ReplicaSet or Deployment) and easily kill one off to restart it somewhere else.
One of the high-end virtualization solutions might be able to do what you’re asking, but keeping a program running forever forever is pretty hard, particularly in a scripting language like Python. (How do you update the program? How do you update the underlying OS, when it needs to reboot to take a kernel update?)

Python R/W to text file network [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
What could happen if multiple users run the same copies of python script which designed to R/W data to a single text file store in network device at the same time?
Will the processes stop working?
If so, what could be the solution?
It can happen many bad things, I don't think the processes stop working, not at least because of concurrent access to file a file, but what could happen is and inconsistent file creation: for example, if one processes write hello, and there is a concurrent access to the file, you might get a line like hhelllolo
A solution I can see is, use a database as suggested, or, create a mechanism for locking the file to concurrent accesses (which might be cumbersome because you're working on network, not the same computer)
Another solution I can think of is create a server side simple script who handle the requests and lock the file for concurrent access. This is almost the same solution as using a database, you'll be creating an storage system from scratch so why bother :)
Hope this helps!

Finding the least busy open wireless network: which language to pick for this weekend project? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am a web developer (PHP/Javascript) and to increase my skill set, I would like to learn a new language. I have a simple test project in mind for this, so I can learn more about (wireless) networks and Linux, something I'm interested in as well.
I have specced out my project like this:
Look at all the open wireless networks in my area, and determine which one is the least busy (i.e. has the least data traffic), then list its ESSID. Do this by putting the wireless interface in monitor mode, and collect statistics about which access point receives/transmits the least TCP packets.
I think this would be a fun, simple way to get the "best" access point to connect to. I'm sure there are better ways to reach that goal, but this would cover all the things I want to learn about.
I am working in Ubuntu, and would like to learn Python or Ruby with this project. I have done a bit of research, and I think I'll need (a wrapper for) libpcap to sample the amount of data. I would also need to address iwconfig to change to the next channel, and look for packets there.
So, my question is: is there an ideal language for this? Is it possible to do this "inside" a language, without having to break out of it to issue a command line command like "iwconfig"? Any advice in general?
My preference is Ruby, and that is because it is my preference. However, there are lots of libraries availble in each language. See:
http://www.scribd.com/doc/56319311/Programming-Wireless-Security-32813
also
Which of these scripting languages is more appropriate for pen-testing?
I don't know much about Ruby, but I'm sure that Python could do what you want. In regards to stepping down into OS/CLI land, I would have a look at the os and subprocess modules. The subprocess module will let you call arbitrary binaries (such as iwconfig) from python and collect their results.
Python is fun to learn. Good luck.

Categories

Resources