Sometimes we might want to make a request to a website programmatically. Instead of having to visit the page in the browser. In Python we can to it the following way.
Here is an example of the most basic usage of the socket module. It connects to a port and prints out the response.
@@ -95,8 +107,6 @@ print s.recv(1024)
# Here we close the socket.
s.close
```
If you need to check all 65535 ports this might take some time. If a packet is sent and recieved that makes it 65535 seconds, it translates into about 18 hours. So to solve that we can run the a function in new threads.
@@ -107,7 +117,7 @@ pool = ThreadPool(300)
results=pool.map(function,array)
```
Read more about parallellism here: http://chriskiehl.com/article/parallelism-in-one-line/
Read more about parallellism here: [http://chriskiehl.com/article/parallelism-in-one-line/](http://chriskiehl.com/article/parallelism-in-one-line/)
## Connecting to SMTP
@@ -120,7 +130,6 @@ The `\r` here is fundamental!!