pidconnectioninfos


Namepidconnectioninfos JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/pidconnectioninfos
SummaryFinds processes holding files/ports open, as well as all generations of children
upload_time2024-03-24 11:29:54
maintainerNone
docs_urlNone
authorJohannes Fischer
requires_pythonNone
licenseMIT
keywords process data
VCS
bugtrack_url
requirements flatten_any_dict_iterable_or_whatsoever
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Finds processes holding files/ports open, as well as all generations of children

## pip install pidconnectioninfos

### Tested against Windows 10 / Python 3.11 / Anaconda

### import

```PY 
from pidconnectioninfos import (
    get_all_children_parents_this_python_process,
    get_all_children_this_python_process,
    get_all_imagenames_and_pid,
    get_all_pids_from_image,
    get_all_pids_from_main_processes,
    get_processes_and_children,
    get_processes_and_children_and_netstat,
    is_process_alive,
    is_subprocess_alive,
    get_procs_with_open_file_pids_only,
    get_network_connections_from_process,
)
import subprocess

cmp = subprocess.Popen( # for tests below
    "ping -i 250 -n 100000 google.com",
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    shell=False,
)
import os
```
### get_all_children_parents_this_python_process()

```PY 
#     Returns all the children and parents of the current Python process.
#     :return: A dictionary containing the children and parents of the current Python process.
#              The dictionary has the following structure:
#              {
#                  "children": [list of child process IDs],
#                  "parents": [list of parent process IDs]
#              }
#     :rtype: dict

allpy = get_all_children_parents_this_python_process()
print(allpy)
(
    {
        (
            "ipython.exe",
            "ipython  -i _____t...",
            18332,
        ): {
            (
                "python.exe",
                "C:\\ProgramData\\anaco...",
                18152,
            ): {
                ("PING.EXE", "ping -i 250 -n 100000 google.com", 14984): -1,
                (
                    "WMIC.exe",
                    "wmic process where (ParentProcessId=18152) get Caption,ProcessId,CommandLine",
                    10864,
                ): -1,
            }
        }
    },
    {
        (
            "ipython.exe",
            "ipython  -i _____t...",
            18332,
        ): [
            (
                0,
                "python.exe",
                "C:\\ProgramData\\anaco...",
                18152,
            ),
            (1, "PING.EXE", "ping -i 250 -n 100000 google.com", 14984),
            (
                0,
                "WMIC.exe",
                "wmic process where (ParentProcessId=18152) get Caption,ProcessId,CommandLine",
                10864,
            ),
        ]
    },
)
```

### get_all_children_this_python_process()

```PY 
#     Returns all the (nested) children processes of the current Python process.

#     :return: A list of Process objects representing the children processes.
#     :rtype: List[Process]
```


### get_all_children_this_python_process()
```PY 
(
    {
        (
            "python.exe",
            "C:\\ProgramData\\anaconda3\\envs\\a0\\...",
            18152,
        ): {
            ("PING.EXE", "ping -i 250 -n 100000 google.com", 14984): -1,
            (
                "WMIC.exe",
                "wmic process where (ParentProcessId=18152) get Caption,ProcessId,CommandLine",
                25496,
            ): -1,
        }
    },
    {
        (
            "python.exe",
            "C:\\ProgramData\\anaconda3\\envs\\a0\\python.exe C:\\ProgramDa...",
            18152,
        ): [
            (0, "PING.EXE", "ping -i 250 -n 100000 google.com", 14984),
            (
                0,
                "WMIC.exe",
                "wmic process where (ParentProcessId=18152) get Caption,ProcessId,CommandLine",
                25496,
            ),
        ]
    },
)
```

### get_all_imagenames_and_pid()
```PY 

#     Get all image names and their corresponding process IDs.
get_all_imagenames_and_pid()
# ...
# ['chrome.exe', 16964],
# ['cmd.exe', 4176],
# ['conhost.exe', 24096],
# ['OpenConsole.exe', 544],
# ['cmd.exe', 25056],
# ['vtm.exe', 18304],
# ['cmd.exe', 25576],
# ['ipython.exe', 18332],
# ['python.exe', 18152],
#  ...
```


### get_all_pids_from_image(imagefile: str = 'chrome.exe')

```PY 
#     Get all process IDs associated with a specific image file.
#     :param imagefile: The name of the image file to search for process IDs (default is "chrome.exe")
#     :type imagefile: str
#     :return: A list of process IDs associated with the specified image file
#     :rtype: list
allchromepids = get_all_pids_from_image(imagefile="chrome.exe")

[
    18608,
    4796,
    19256,
    19004,
    11532,
    19208,
    2944,
    1160,
    19032,
    13208,
    16084,
    11688,
    10140,
    17048,
    11316,
    940,
    5600,
    6660,
    19524,
    18620,
    10060,
    10328,
    13744,
    22452,
    20752,
    22248,
    592,
    21136,
    18108,
    18492,
    18676,
    7788,
    16964,
    22932,
    19788,
]
```
### get_all_pids_from_main_processes()
```PY 
#     Gets all process IDs from the main processes and returns a list of integers.

allpids = get_all_pids_from_main_processes()
[
    0,
    4,
    64,
    132,
    468,
    688,
    776,
    784,
    888,
    312,
    488,
    496,
    952,
    8,
    504,
    1068,
    1148,
    1200,
    1272,
    1400,
    1416,
    1528,
    1536,
    1544,
    1572,
    1660,
    1712,
    1748,
    1820,
    1916,
    2036,
    1260,
    2080,
    2216,
    2224,
    2232,
    2252,
    2316,
    2376,
    2428,
    2436,
    2484,
    2492,
    2668,
    2852,
    2920,
    3008,
    1164,
    3256,
    3440,
    3448,
    3576,
    3636,
    3712,
    4220,
    4256,
    4296,
    4372,
    4460,
    4468,
    4588,
    4700,
    4724,
    4732,
    4740,
    4756,
    4768,
    4784,
    4820,
    4828,
    4876,
    4924,
    4932,
    4940,
    4948,
    4964,
    5024,
    4244,
    5124,
    5152,
    5,
    ...,
]
```

### get_processes_and_children(pids_to_search: list | tuple | int | None = None, always_ignore: tuple = (0, 4))
```PY 
#     Get the processes and their children based on the provided process IDs to search and the processes to always ignore.
#     If no IDs are provided, it will default to searching through a range of 65536 IDs.
#     The function returns two dictionaries: `resultchildren` containing the children of each process as a "family tree", and `resultchildren_flat` containing a flattened version of the children relationship.

procs_and_kids = get_processes_and_children(allchromepids, always_ignore=(0, 4))
{
    (
        "chrome.exe",
        '"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"',
        1968,
    ): {
        (
            "chrome.exe",
            '"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" --type=crashpad-handler ...")',
            1968,
        ): -1
    }
}
```
### get_processes_and_children_and_netstat(pids_to_search: list | tuple | int | None = None, always_ignore: tuple = (0, 4))
```PY 
#     Retrieves a tree of processes, their children, and netstat connection information.
#     Args:
#         pids_to_search (Optional[List[int]]): A list of process IDs to search for. Defaults to None.
#         always_ignore (Tuple[int]): A tuple of process IDs to always ignore. Defaults to (0, 4).
#     Returns:
#         Tuple[Dict[int, Dict[str, Any]], List[Dict[str, Any]], Dict[int, List[List[str]]], Dict[int, List[List[str]]]]:
#             - A tree of processes and their children, represented as a dictionary.
#             - A flat list of processes and their children, represented as a list of dictionaries.
#             - A dictionary of established connections, with the process ID as the key and a list of connection information as the value.
#             - A dictionary of all connection data, with the process ID as the key and a list of connection information as the value.


procs_and_kids_netstat = get_processes_and_children_and_netstat(
    allchromepids, always_ignore=(0, 4)
)
{
    688: [
        ("TCP", "127.0.0.1:5835", "0.0.0.0:0", "LISTENING", 688),
        ("TCP", "127.0.0.1:5835", "127.0.0.1:53324", "ESTABLISHED", 688),
        ...,
        ("UDP", "0.0.0.0:61382", "*:*", 688),
        ("UDP", "[::]:61382", "*:*", 688),
    ],
    13380: [
        ("TCP", "127.0.0.1:5845", "0.0.0.0:0", "LISTENING", 13380),
        ("TCP", "127.0.0.1:5845", "127.0.0.1:53334", "ESTABLISHED", 13380),
        ...,
        ("UDP", "[::]:58688", "*:*", 13380),
    ],
    5140: [
        ("TCP", "127.0.0.1:31100", "0.0.0.0:0", "LISTENING", 5140),
        ("TCP", "127.0.0.1:49668", "127.0.0.1:31104", "ESTABLISHED", 5140),
        ("TCP", "127.0.0.1:49680", "127.0.0.1:31104", "ESTABLISHED", 5140),
    ],
    5208: [
        ("TCP", "127.0.0.1:49726", "127.0.0.1:65001", "ESTABLISHED", 5208),
        ("TCP", "127.0.0.1:65001", "0.0.0.0:0", "LISTENING", 5208),
        ("TCP", "127.0.0.1:65001", "127.0.0.1:49726", "ESTABLISHED", 5208),
        ("UDP", "0.0.0.0:59435", "*:*", 5208),
        ...,
        ("UDP", "[::]:59436", "*:*", 5208),
        ("UDP", "[::1]:5353", "*:*", 5208),
    ],
    9844: [
        ("TCP", "127.0.0.1:49728", "0.0.0.0:0", "LISTENING", 9844),
        ("TCP", "127.0.0.1:49728", "127.0.0.1:49737", "ESTABLISHED", 9844),
        ("UDP", "127.0.0.1:10010", "*:*", 9844),
    ],
    13932: [("TCP", "127.0.0.1:49737", "127.0.0.1:49728", "ESTABLISHED", 13932)],
}
```

### is_process_alive(pid: int)

```PY 
#     A function that checks if a process with a given Process ID is alive.
#     Parameters:
#         - pid: int, the Process ID of the process to check.
#     Returns:
#         - tuple: (bool, tuple) where the boolean indicates if the process is alive, and the tuple contains information about the process.
```

### is_process_alive(pid=os.getpid())
```PY 
(True, ("python.exe", "C:\\ProgramData\\anaconda3\\envs\\a0\\python.exe ", ...))
```


### is_subprocess_alive(cmp: subprocess.Popen)
```PY 
#     Check if a subprocess is still alive.

#     Parameters:
#         cmp (subprocess.Popen): The subprocess to check.

#     Returns:
#         bool: True if the subprocess is still alive, False otherwise.

is_subprocess_alive(cmp=cmp)
True
```

### get_procs_with_open_file_pids_only(path):
```PY 
#     """
#     Get the list of process IDs that have an open file at the specified path.

#     Args:
#         path (str): The path of the file.

#     Returns:
#         list: A list of process IDs that have the file open.
a = get_procs_with_open_file_pids_only(path=r"C:\uber.xlsx")
[18280]

b = get_procs_with_open_file_pids_only(path=r"C:\planotreinar.mp4")
[17120]
(
    {
        (
            "vlc.exe",
            '"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe" --started-from-file "C:\\planotreinar.mp4"',
            25220,
        ): -1
    },
    {
        (
            "vlc.exe",
            '"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe" --started-from-file "C:\\planotreinar.mp4"',
            25220,
        ): [(0,)]
    },
)


(
    {
        (
            "EXCEL.EXE",
            '"C:\\Program Files\\Microsoft Office\\Root\\Office16\\EXCEL.EXE" "C:\\tempTest2.csv"',
            2928,
        ): {("splwow64.exe", "C:\\WINDOWS\\splwow64.exe 12288", 10112): -1}
    },
    ...,
)
```

### get_processes_and_children_and_netstat / get_processes_and_children
```PY 
procs_and_kids_netstat = get_processes_and_children_and_netstat(a, always_ignore=(0, 4))
procs_and_kids = get_processes_and_children(b, always_ignore=(0, 4))
"""
Retrieves a tree of processes, their children, and netstat connection information.

Args:
    pids_to_search (Optional[List[int]]): A list of process IDs to search for. Defaults to None.
    always_ignore (Tuple[int]): A tuple of process IDs to always ignore. Defaults to (0, 4).

Returns:
    Tuple[Dict[int, Dict[str, Any]], List[Dict[str, Any]], Dict[int, List[List[str]]], Dict[int, List[List[str]]]]:
        - A tree of processes and their children, represented as a dictionary.
        - A flat list of processes and their children, represented as a list of dictionaries.
        - A dictionary of established connections, with the process ID as the key and a list of connection information as the value.
        - A dictionary of all connection data, with the process ID as the key and a list of connection information as the value."""

ports = [5555, 5037, 17476, 5835, 5845, 443, 80]
fatr = get_network_connections_from_process(ports=ports, always_ignore=(0, 4))
print(fatr)
{
    10348: {
        "family_tree": {
            ("adb.exe", "adb -L tcp:5037 fork-server server --reply-fd 616", 10348): -1
        },
        "flat_tree": {
            ("adb.exe", "adb -L tcp:5037 fork-server server --reply-fd 616", 10348): [
                (0,)
            ]
        },
        "found_ports": {5845, 5835, 5037},
    },
    688: {
        "family_tree": {
            (
                "HD-Player.exe",
                '"C:\\\\Program Files\\\\BlueStacks_nxt\\\\HD-Player.exe" "--instance" "Rvc64_28"',
                688,
            ): -1
        },
        "flat_tree": {
            (
                "HD-Player.exe",
                '"C:\\\\Program Files\\\\BlueStacks_nxt\\\\HD-Player.exe" "--instance" "Rvc64_28"',
                688,
            ): [(0,)]
        },
        "found_ports": {5835, 443},
    },
    13380: {
        "family_tree": {
            (
                "HD-Player.exe",
                '"C:\\\\Program Files\\\\BlueStacks_nxt\\\\HD-Player.exe" "--instance" "Rvc64_29"',
                13380,
            ): -1
        },
        "flat_tree": {
            (
                "HD-Player.exe",
                '"C:\\\\Program Files\\\\BlueStacks_nxt\\\\HD-Player.exe" "--instance" "Rvc64_29"',
                13380,
            ): [(0,)]
        },
        "found_ports": {443, 5845},
    },
    5440: {
        "family_tree": {
            (
                "svchost.exe",
                "C:\\WINDOWS\\system32\\svchost.exe -k netsvcs -p -s WpnService",
                5440,
            ): -1
        },
        "flat_tree": {
            (
                "svchost.exe",
                "C:\\WINDOWS\\system32\\svchost.exe -k netsvcs -p -s WpnService",
                5440,
            ): [(0,)]
        },
        "found_ports": {443},
    },
    2304: (...,),
}
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/pidconnectioninfos",
    "name": "pidconnectioninfos",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "process, data",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/73/37/7ab194eab42206b1f5cf0e5d048a46232b4af403220a3137c6a0303ee029/pidconnectioninfos-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# Finds processes holding files/ports open, as well as all generations of children\r\n\r\n## pip install pidconnectioninfos\r\n\r\n### Tested against Windows 10 / Python 3.11 / Anaconda\r\n\r\n### import\r\n\r\n```PY \r\nfrom pidconnectioninfos import (\r\n    get_all_children_parents_this_python_process,\r\n    get_all_children_this_python_process,\r\n    get_all_imagenames_and_pid,\r\n    get_all_pids_from_image,\r\n    get_all_pids_from_main_processes,\r\n    get_processes_and_children,\r\n    get_processes_and_children_and_netstat,\r\n    is_process_alive,\r\n    is_subprocess_alive,\r\n    get_procs_with_open_file_pids_only,\r\n    get_network_connections_from_process,\r\n)\r\nimport subprocess\r\n\r\ncmp = subprocess.Popen( # for tests below\r\n    \"ping -i 250 -n 100000 google.com\",\r\n    stdout=subprocess.PIPE,\r\n    stderr=subprocess.PIPE,\r\n    shell=False,\r\n)\r\nimport os\r\n```\r\n### get_all_children_parents_this_python_process()\r\n\r\n```PY \r\n#     Returns all the children and parents of the current Python process.\r\n#     :return: A dictionary containing the children and parents of the current Python process.\r\n#              The dictionary has the following structure:\r\n#              {\r\n#                  \"children\": [list of child process IDs],\r\n#                  \"parents\": [list of parent process IDs]\r\n#              }\r\n#     :rtype: dict\r\n\r\nallpy = get_all_children_parents_this_python_process()\r\nprint(allpy)\r\n(\r\n    {\r\n        (\r\n            \"ipython.exe\",\r\n            \"ipython  -i _____t...\",\r\n            18332,\r\n        ): {\r\n            (\r\n                \"python.exe\",\r\n                \"C:\\\\ProgramData\\\\anaco...\",\r\n                18152,\r\n            ): {\r\n                (\"PING.EXE\", \"ping -i 250 -n 100000 google.com\", 14984): -1,\r\n                (\r\n                    \"WMIC.exe\",\r\n                    \"wmic process where (ParentProcessId=18152) get Caption,ProcessId,CommandLine\",\r\n                    10864,\r\n                ): -1,\r\n            }\r\n        }\r\n    },\r\n    {\r\n        (\r\n            \"ipython.exe\",\r\n            \"ipython  -i _____t...\",\r\n            18332,\r\n        ): [\r\n            (\r\n                0,\r\n                \"python.exe\",\r\n                \"C:\\\\ProgramData\\\\anaco...\",\r\n                18152,\r\n            ),\r\n            (1, \"PING.EXE\", \"ping -i 250 -n 100000 google.com\", 14984),\r\n            (\r\n                0,\r\n                \"WMIC.exe\",\r\n                \"wmic process where (ParentProcessId=18152) get Caption,ProcessId,CommandLine\",\r\n                10864,\r\n            ),\r\n        ]\r\n    },\r\n)\r\n```\r\n\r\n### get_all_children_this_python_process()\r\n\r\n```PY \r\n#     Returns all the (nested) children processes of the current Python process.\r\n\r\n#     :return: A list of Process objects representing the children processes.\r\n#     :rtype: List[Process]\r\n```\r\n\r\n\r\n### get_all_children_this_python_process()\r\n```PY \r\n(\r\n    {\r\n        (\r\n            \"python.exe\",\r\n            \"C:\\\\ProgramData\\\\anaconda3\\\\envs\\\\a0\\\\...\",\r\n            18152,\r\n        ): {\r\n            (\"PING.EXE\", \"ping -i 250 -n 100000 google.com\", 14984): -1,\r\n            (\r\n                \"WMIC.exe\",\r\n                \"wmic process where (ParentProcessId=18152) get Caption,ProcessId,CommandLine\",\r\n                25496,\r\n            ): -1,\r\n        }\r\n    },\r\n    {\r\n        (\r\n            \"python.exe\",\r\n            \"C:\\\\ProgramData\\\\anaconda3\\\\envs\\\\a0\\\\python.exe C:\\\\ProgramDa...\",\r\n            18152,\r\n        ): [\r\n            (0, \"PING.EXE\", \"ping -i 250 -n 100000 google.com\", 14984),\r\n            (\r\n                0,\r\n                \"WMIC.exe\",\r\n                \"wmic process where (ParentProcessId=18152) get Caption,ProcessId,CommandLine\",\r\n                25496,\r\n            ),\r\n        ]\r\n    },\r\n)\r\n```\r\n\r\n### get_all_imagenames_and_pid()\r\n```PY \r\n\r\n#     Get all image names and their corresponding process IDs.\r\nget_all_imagenames_and_pid()\r\n# ...\r\n# ['chrome.exe', 16964],\r\n# ['cmd.exe', 4176],\r\n# ['conhost.exe', 24096],\r\n# ['OpenConsole.exe', 544],\r\n# ['cmd.exe', 25056],\r\n# ['vtm.exe', 18304],\r\n# ['cmd.exe', 25576],\r\n# ['ipython.exe', 18332],\r\n# ['python.exe', 18152],\r\n#  ...\r\n```\r\n\r\n\r\n### get_all_pids_from_image(imagefile: str = 'chrome.exe')\r\n\r\n```PY \r\n#     Get all process IDs associated with a specific image file.\r\n#     :param imagefile: The name of the image file to search for process IDs (default is \"chrome.exe\")\r\n#     :type imagefile: str\r\n#     :return: A list of process IDs associated with the specified image file\r\n#     :rtype: list\r\nallchromepids = get_all_pids_from_image(imagefile=\"chrome.exe\")\r\n\r\n[\r\n    18608,\r\n    4796,\r\n    19256,\r\n    19004,\r\n    11532,\r\n    19208,\r\n    2944,\r\n    1160,\r\n    19032,\r\n    13208,\r\n    16084,\r\n    11688,\r\n    10140,\r\n    17048,\r\n    11316,\r\n    940,\r\n    5600,\r\n    6660,\r\n    19524,\r\n    18620,\r\n    10060,\r\n    10328,\r\n    13744,\r\n    22452,\r\n    20752,\r\n    22248,\r\n    592,\r\n    21136,\r\n    18108,\r\n    18492,\r\n    18676,\r\n    7788,\r\n    16964,\r\n    22932,\r\n    19788,\r\n]\r\n```\r\n### get_all_pids_from_main_processes()\r\n```PY \r\n#     Gets all process IDs from the main processes and returns a list of integers.\r\n\r\nallpids = get_all_pids_from_main_processes()\r\n[\r\n    0,\r\n    4,\r\n    64,\r\n    132,\r\n    468,\r\n    688,\r\n    776,\r\n    784,\r\n    888,\r\n    312,\r\n    488,\r\n    496,\r\n    952,\r\n    8,\r\n    504,\r\n    1068,\r\n    1148,\r\n    1200,\r\n    1272,\r\n    1400,\r\n    1416,\r\n    1528,\r\n    1536,\r\n    1544,\r\n    1572,\r\n    1660,\r\n    1712,\r\n    1748,\r\n    1820,\r\n    1916,\r\n    2036,\r\n    1260,\r\n    2080,\r\n    2216,\r\n    2224,\r\n    2232,\r\n    2252,\r\n    2316,\r\n    2376,\r\n    2428,\r\n    2436,\r\n    2484,\r\n    2492,\r\n    2668,\r\n    2852,\r\n    2920,\r\n    3008,\r\n    1164,\r\n    3256,\r\n    3440,\r\n    3448,\r\n    3576,\r\n    3636,\r\n    3712,\r\n    4220,\r\n    4256,\r\n    4296,\r\n    4372,\r\n    4460,\r\n    4468,\r\n    4588,\r\n    4700,\r\n    4724,\r\n    4732,\r\n    4740,\r\n    4756,\r\n    4768,\r\n    4784,\r\n    4820,\r\n    4828,\r\n    4876,\r\n    4924,\r\n    4932,\r\n    4940,\r\n    4948,\r\n    4964,\r\n    5024,\r\n    4244,\r\n    5124,\r\n    5152,\r\n    5,\r\n    ...,\r\n]\r\n```\r\n\r\n### get_processes_and_children(pids_to_search: list | tuple | int | None = None, always_ignore: tuple = (0, 4))\r\n```PY \r\n#     Get the processes and their children based on the provided process IDs to search and the processes to always ignore.\r\n#     If no IDs are provided, it will default to searching through a range of 65536 IDs.\r\n#     The function returns two dictionaries: `resultchildren` containing the children of each process as a \"family tree\", and `resultchildren_flat` containing a flattened version of the children relationship.\r\n\r\nprocs_and_kids = get_processes_and_children(allchromepids, always_ignore=(0, 4))\r\n{\r\n    (\r\n        \"chrome.exe\",\r\n        '\"C:\\\\Program Files (x86)\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe\"',\r\n        1968,\r\n    ): {\r\n        (\r\n            \"chrome.exe\",\r\n            '\"C:\\\\Program Files (x86)\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe\" --type=crashpad-handler ...\")',\r\n            1968,\r\n        ): -1\r\n    }\r\n}\r\n```\r\n### get_processes_and_children_and_netstat(pids_to_search: list | tuple | int | None = None, always_ignore: tuple = (0, 4))\r\n```PY \r\n#     Retrieves a tree of processes, their children, and netstat connection information.\r\n#     Args:\r\n#         pids_to_search (Optional[List[int]]): A list of process IDs to search for. Defaults to None.\r\n#         always_ignore (Tuple[int]): A tuple of process IDs to always ignore. Defaults to (0, 4).\r\n#     Returns:\r\n#         Tuple[Dict[int, Dict[str, Any]], List[Dict[str, Any]], Dict[int, List[List[str]]], Dict[int, List[List[str]]]]:\r\n#             - A tree of processes and their children, represented as a dictionary.\r\n#             - A flat list of processes and their children, represented as a list of dictionaries.\r\n#             - A dictionary of established connections, with the process ID as the key and a list of connection information as the value.\r\n#             - A dictionary of all connection data, with the process ID as the key and a list of connection information as the value.\r\n\r\n\r\nprocs_and_kids_netstat = get_processes_and_children_and_netstat(\r\n    allchromepids, always_ignore=(0, 4)\r\n)\r\n{\r\n    688: [\r\n        (\"TCP\", \"127.0.0.1:5835\", \"0.0.0.0:0\", \"LISTENING\", 688),\r\n        (\"TCP\", \"127.0.0.1:5835\", \"127.0.0.1:53324\", \"ESTABLISHED\", 688),\r\n        ...,\r\n        (\"UDP\", \"0.0.0.0:61382\", \"*:*\", 688),\r\n        (\"UDP\", \"[::]:61382\", \"*:*\", 688),\r\n    ],\r\n    13380: [\r\n        (\"TCP\", \"127.0.0.1:5845\", \"0.0.0.0:0\", \"LISTENING\", 13380),\r\n        (\"TCP\", \"127.0.0.1:5845\", \"127.0.0.1:53334\", \"ESTABLISHED\", 13380),\r\n        ...,\r\n        (\"UDP\", \"[::]:58688\", \"*:*\", 13380),\r\n    ],\r\n    5140: [\r\n        (\"TCP\", \"127.0.0.1:31100\", \"0.0.0.0:0\", \"LISTENING\", 5140),\r\n        (\"TCP\", \"127.0.0.1:49668\", \"127.0.0.1:31104\", \"ESTABLISHED\", 5140),\r\n        (\"TCP\", \"127.0.0.1:49680\", \"127.0.0.1:31104\", \"ESTABLISHED\", 5140),\r\n    ],\r\n    5208: [\r\n        (\"TCP\", \"127.0.0.1:49726\", \"127.0.0.1:65001\", \"ESTABLISHED\", 5208),\r\n        (\"TCP\", \"127.0.0.1:65001\", \"0.0.0.0:0\", \"LISTENING\", 5208),\r\n        (\"TCP\", \"127.0.0.1:65001\", \"127.0.0.1:49726\", \"ESTABLISHED\", 5208),\r\n        (\"UDP\", \"0.0.0.0:59435\", \"*:*\", 5208),\r\n        ...,\r\n        (\"UDP\", \"[::]:59436\", \"*:*\", 5208),\r\n        (\"UDP\", \"[::1]:5353\", \"*:*\", 5208),\r\n    ],\r\n    9844: [\r\n        (\"TCP\", \"127.0.0.1:49728\", \"0.0.0.0:0\", \"LISTENING\", 9844),\r\n        (\"TCP\", \"127.0.0.1:49728\", \"127.0.0.1:49737\", \"ESTABLISHED\", 9844),\r\n        (\"UDP\", \"127.0.0.1:10010\", \"*:*\", 9844),\r\n    ],\r\n    13932: [(\"TCP\", \"127.0.0.1:49737\", \"127.0.0.1:49728\", \"ESTABLISHED\", 13932)],\r\n}\r\n```\r\n\r\n### is_process_alive(pid: int)\r\n\r\n```PY \r\n#     A function that checks if a process with a given Process ID is alive.\r\n#     Parameters:\r\n#         - pid: int, the Process ID of the process to check.\r\n#     Returns:\r\n#         - tuple: (bool, tuple) where the boolean indicates if the process is alive, and the tuple contains information about the process.\r\n```\r\n\r\n### is_process_alive(pid=os.getpid())\r\n```PY \r\n(True, (\"python.exe\", \"C:\\\\ProgramData\\\\anaconda3\\\\envs\\\\a0\\\\python.exe \", ...))\r\n```\r\n\r\n\r\n### is_subprocess_alive(cmp: subprocess.Popen)\r\n```PY \r\n#     Check if a subprocess is still alive.\r\n\r\n#     Parameters:\r\n#         cmp (subprocess.Popen): The subprocess to check.\r\n\r\n#     Returns:\r\n#         bool: True if the subprocess is still alive, False otherwise.\r\n\r\nis_subprocess_alive(cmp=cmp)\r\nTrue\r\n```\r\n\r\n### get_procs_with_open_file_pids_only(path):\r\n```PY \r\n#     \"\"\"\r\n#     Get the list of process IDs that have an open file at the specified path.\r\n\r\n#     Args:\r\n#         path (str): The path of the file.\r\n\r\n#     Returns:\r\n#         list: A list of process IDs that have the file open.\r\na = get_procs_with_open_file_pids_only(path=r\"C:\\uber.xlsx\")\r\n[18280]\r\n\r\nb = get_procs_with_open_file_pids_only(path=r\"C:\\planotreinar.mp4\")\r\n[17120]\r\n(\r\n    {\r\n        (\r\n            \"vlc.exe\",\r\n            '\"C:\\\\Program Files\\\\VideoLAN\\\\VLC\\\\vlc.exe\" --started-from-file \"C:\\\\planotreinar.mp4\"',\r\n            25220,\r\n        ): -1\r\n    },\r\n    {\r\n        (\r\n            \"vlc.exe\",\r\n            '\"C:\\\\Program Files\\\\VideoLAN\\\\VLC\\\\vlc.exe\" --started-from-file \"C:\\\\planotreinar.mp4\"',\r\n            25220,\r\n        ): [(0,)]\r\n    },\r\n)\r\n\r\n\r\n(\r\n    {\r\n        (\r\n            \"EXCEL.EXE\",\r\n            '\"C:\\\\Program Files\\\\Microsoft Office\\\\Root\\\\Office16\\\\EXCEL.EXE\" \"C:\\\\tempTest2.csv\"',\r\n            2928,\r\n        ): {(\"splwow64.exe\", \"C:\\\\WINDOWS\\\\splwow64.exe 12288\", 10112): -1}\r\n    },\r\n    ...,\r\n)\r\n```\r\n\r\n### get_processes_and_children_and_netstat / get_processes_and_children\r\n```PY \r\nprocs_and_kids_netstat = get_processes_and_children_and_netstat(a, always_ignore=(0, 4))\r\nprocs_and_kids = get_processes_and_children(b, always_ignore=(0, 4))\r\n\"\"\"\r\nRetrieves a tree of processes, their children, and netstat connection information.\r\n\r\nArgs:\r\n    pids_to_search (Optional[List[int]]): A list of process IDs to search for. Defaults to None.\r\n    always_ignore (Tuple[int]): A tuple of process IDs to always ignore. Defaults to (0, 4).\r\n\r\nReturns:\r\n    Tuple[Dict[int, Dict[str, Any]], List[Dict[str, Any]], Dict[int, List[List[str]]], Dict[int, List[List[str]]]]:\r\n        - A tree of processes and their children, represented as a dictionary.\r\n        - A flat list of processes and their children, represented as a list of dictionaries.\r\n        - A dictionary of established connections, with the process ID as the key and a list of connection information as the value.\r\n        - A dictionary of all connection data, with the process ID as the key and a list of connection information as the value.\"\"\"\r\n\r\nports = [5555, 5037, 17476, 5835, 5845, 443, 80]\r\nfatr = get_network_connections_from_process(ports=ports, always_ignore=(0, 4))\r\nprint(fatr)\r\n{\r\n    10348: {\r\n        \"family_tree\": {\r\n            (\"adb.exe\", \"adb -L tcp:5037 fork-server server --reply-fd 616\", 10348): -1\r\n        },\r\n        \"flat_tree\": {\r\n            (\"adb.exe\", \"adb -L tcp:5037 fork-server server --reply-fd 616\", 10348): [\r\n                (0,)\r\n            ]\r\n        },\r\n        \"found_ports\": {5845, 5835, 5037},\r\n    },\r\n    688: {\r\n        \"family_tree\": {\r\n            (\r\n                \"HD-Player.exe\",\r\n                '\"C:\\\\\\\\Program Files\\\\\\\\BlueStacks_nxt\\\\\\\\HD-Player.exe\" \"--instance\" \"Rvc64_28\"',\r\n                688,\r\n            ): -1\r\n        },\r\n        \"flat_tree\": {\r\n            (\r\n                \"HD-Player.exe\",\r\n                '\"C:\\\\\\\\Program Files\\\\\\\\BlueStacks_nxt\\\\\\\\HD-Player.exe\" \"--instance\" \"Rvc64_28\"',\r\n                688,\r\n            ): [(0,)]\r\n        },\r\n        \"found_ports\": {5835, 443},\r\n    },\r\n    13380: {\r\n        \"family_tree\": {\r\n            (\r\n                \"HD-Player.exe\",\r\n                '\"C:\\\\\\\\Program Files\\\\\\\\BlueStacks_nxt\\\\\\\\HD-Player.exe\" \"--instance\" \"Rvc64_29\"',\r\n                13380,\r\n            ): -1\r\n        },\r\n        \"flat_tree\": {\r\n            (\r\n                \"HD-Player.exe\",\r\n                '\"C:\\\\\\\\Program Files\\\\\\\\BlueStacks_nxt\\\\\\\\HD-Player.exe\" \"--instance\" \"Rvc64_29\"',\r\n                13380,\r\n            ): [(0,)]\r\n        },\r\n        \"found_ports\": {443, 5845},\r\n    },\r\n    5440: {\r\n        \"family_tree\": {\r\n            (\r\n                \"svchost.exe\",\r\n                \"C:\\\\WINDOWS\\\\system32\\\\svchost.exe -k netsvcs -p -s WpnService\",\r\n                5440,\r\n            ): -1\r\n        },\r\n        \"flat_tree\": {\r\n            (\r\n                \"svchost.exe\",\r\n                \"C:\\\\WINDOWS\\\\system32\\\\svchost.exe -k netsvcs -p -s WpnService\",\r\n                5440,\r\n            ): [(0,)]\r\n        },\r\n        \"found_ports\": {443},\r\n    },\r\n    2304: (...,),\r\n}\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Finds processes holding files/ports open, as well as all generations of children",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/pidconnectioninfos"
    },
    "split_keywords": [
        "process",
        " data"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5765528431346830cf677659890bee77080a32052ba2795ef9eafe4597d5f50a",
                "md5": "cd052228084e5de8137868db1949a178",
                "sha256": "3ee7f50b52cfb9b2475a4f79049f28d461e17f2d1110a2b425895abd201fffd1"
            },
            "downloads": -1,
            "filename": "pidconnectioninfos-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cd052228084e5de8137868db1949a178",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 15435,
            "upload_time": "2024-03-24T11:29:52",
            "upload_time_iso_8601": "2024-03-24T11:29:52.110125Z",
            "url": "https://files.pythonhosted.org/packages/57/65/528431346830cf677659890bee77080a32052ba2795ef9eafe4597d5f50a/pidconnectioninfos-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "73377ab194eab42206b1f5cf0e5d048a46232b4af403220a3137c6a0303ee029",
                "md5": "9bf3faf10d4e6b9f217c403483be6297",
                "sha256": "36133e3d6390a96acd97900640866c6b65016c6ffe00aab98f88c25bf6876a45"
            },
            "downloads": -1,
            "filename": "pidconnectioninfos-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "9bf3faf10d4e6b9f217c403483be6297",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 14931,
            "upload_time": "2024-03-24T11:29:54",
            "upload_time_iso_8601": "2024-03-24T11:29:54.025157Z",
            "url": "https://files.pythonhosted.org/packages/73/37/7ab194eab42206b1f5cf0e5d048a46232b4af403220a3137c6a0303ee029/pidconnectioninfos-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-24 11:29:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "pidconnectioninfos",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "flatten_any_dict_iterable_or_whatsoever",
            "specs": []
        }
    ],
    "lcname": "pidconnectioninfos"
}
        
Elapsed time: 2.48923s