> For the complete documentation index, see [llms.txt](https://notes.programmersecurity.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.programmersecurity.com/python-programs-for-pentesting/python-code-snippets.md).

# 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="/files/u2ebwC4gXU55e4xCuyoh" alt=""><figcaption><p>in this example we supplied 2 command line arguments</p></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.programmersecurity.com/python-programs-for-pentesting/python-code-snippets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
