Commit 4f501109 authored by Philip Linghammar's avatar Philip Linghammar
Browse files

Updates connections.md

Auto commit by GitBook Editor
parent 954f48b5
Loading
Loading
Loading
Loading
+54 −44
Original line number Diff line number Diff line
# Useful Scripts


## Make Request

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.
@@ -52,7 +51,7 @@ req = requests.get("http://site.com", data=values, headers=headers)
```

Here is the documentation  
http://docs.python-requests.org/en/master/user/quickstart/
[http://docs.python-requests.org/en/master/user/quickstart/](http://docs.python-requests.org/en/master/user/quickstart/)

## Read and write to files

@@ -67,6 +66,19 @@ for line in file_open:
```



### Send requests to your proxy \(like Burp\)



```
import os
os.environ['HTTPS_PROXY'] = '<proxyurl>:<port>' 
# http://127.0.0.1:8080 if it is burp
```



## Basic banner-grabber

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!!
s.send('VRFY root \r\n')
```


```python
#!/usr/bin/python
import socket
@@ -181,4 +190,5 @@ for ip in ips:

## Client/Server using sockets

http://programmers.stackexchange.com/questions/171734/difference-between-a-socket-and-a-port
 No newline at end of file
[http://programmers.stackexchange.com/questions/171734/difference-between-a-socket-and-a-port](http://programmers.stackexchange.com/questions/171734/difference-between-a-socket-and-a-port)