# Python Code Snippets

## Code to Send a Get Request to a URL and Print Response and Headers

this code will do a get request on the URL and then print the request headers and response

Below in the target URL i have passed IP address and Injection Point as %s which i will supply on command line

```python
import sys
import requests
from bs4 import BeautifulSoup
import json

def search_friends(ip, param):
    target = "http://%s/ATutor/mods/_standard/social/index_public.php?q=%s" % (ip, param)
    r = requests.get(target)
    s = BeautifulSoup(r.text, 'lxml')
    print()
    print("Request Headers:")
    print(json.dumps(dict(r.request.headers), indent=4))
    print()
    print("Response Headers:")
    print(json.dumps(dict(r.headers), indent=4))
    print()
    print("Response Content:")
    print(s.text)

def main():
    if len(sys.argv) != 3:
        print("Please supply 2 parameters")
        sys.exit(1)
    ip = sys.argv[1]
    inj_str = sys.argv[2]

    search_friends(ip, inj_str)

if __name__ == "__main__":
    main()
```

<figure><img src="https://3420091786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1ZUO45eHY8aMCLJ7OiN%2Fuploads%2FKNh7ZkL4ApvLRrKl7ptx%2Fimage.png?alt=media&#x26;token=6dca03e4-aeb2-4111-a7f4-550b87a746d0" alt=""><figcaption><p>in this example we supplied 2 command line arguments</p></figcaption></figure>
