Showing posts from March, 2015

IP scanning in python

In order to find the IPs using python, we are going to install nmap module. You can installing it, by typing in the terminal the following command : sudo apt-get install python-nmap
import nmap nm = nmap.PortScanner() cidr2 =''a = nm.scan(hosts=cidr2, arguments='-sP') for k,v in a['scan'].iteritems(): if str(v['status']['state']) == 'up': print str(v) try: print str(v['addresses']['ipv4']) + ' => ' + str(v['addresses']['mac']) except: print str(v['addresses']['ipv4']) Output: {'status': {'state': u'up', 'reason': u'conn-refused'}, 'hostname': '', 'addresses': {u'ipv4': u''}} {'status': {'state': u'up', 'reason': u'conn-refused'}, 'hostname': '', 'addresses': {u…

Socket programming in python

Socket programming 'means' server-client model

So,we have to two python script. One for the server and one for the client.
For the server: For the client for the client and server python scripts click hereAs you can see, the client is typing and sending a message and the server is receiving and replying. If either the server or the clientwrites 'exit', then the connection stops.The value of the HOST variable is the IP address of the client and the server... ( you can find IP, by pressing ifconfig in your terminal (for linux users) or by pressing ipconfig incommand prompt(for windows users)).So if you want to achieve a communication between 2 computers (they must be connected in the same network) the steps are very simple:1) In computer (A) you have to run the script for the server (don't forget the HOST variable)2) In computer (B) you have to run the script for the client (don't forget the HOST variable)

Find all .txt files

In this post, you are going to see how to find all .txt files in your computer using python's os module.

You can see the code below:

import os def find_all_txtfiles(): for root, dirs, files in os.walk("/"): for file in files: if file.endswith(".txt"): print(os.path.join(file)) find_all_txtfiles()As you can see it's pretty easy to use this code, in order to find whatever kind of file you want. You only have to change .txt extension .Also, you can narrow your search to a specific directory by adding the path of the directory, that you would like to search.( for root, dirs, files in os.walk("/home/user/Desktop/python") ).