> For the complete documentation index, see [llms.txt](https://www.pentestwiki.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pentestwiki.com/defense-evasion/windows-api/internetopen.md).

# InternetOpen

InternetOpen은 프로세스에서 인터넷을 사용할 수 있도록 세션을 초기화하는 함수입니다.

```cpp
HINTERNET InternetOpenA(
  [in] LPCSTR lpszAgent,
  [in] DWORD  dwAccessType,
  [in] LPCSTR lpszProxy,
  [in] LPCSTR lpszProxyBypass,
  [in] DWORD  dwFlags
);
```

| 인자              | 설명              | 보편적인 값                                                                                                          |
| --------------- | --------------- | --------------------------------------------------------------------------------------------------------------- |
| lpszAgent       | User-Agent      | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 |
| dwAccessType    | 인터넷 연결 방법       | `INTERNET_OPEN_TYPE_DIRECT`                                                                                     |
| lpszProxy       | 프록시 서버 주소       | NULL                                                                                                            |
| lpszProxyBypass | 프록시를 우회할 도메인 목록 | NULL                                                                                                            |
| dwFlags         | 세션 레벨           | 0                                                                                                               |

## Example

```cpp
#include <windows.h>
#include <wininet.h>
#include <iostream>

#pragma comment(lib, "wininet.lib")

int main() {
    // 인터넷 세션 초기화
    HINTERNET hInternet = InternetOpen(
        L"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
        INTERNET_OPEN_TYPE_DIRECT,
        NULL,                     
        NULL,                
        0                    
    );

    // 초기화 실패 예외처리
    if (hInternet == NULL) {
        std::cout << "InternetOpen failed: " << GetLastError() << std::endl;
        return 0;
    }

    std::cout << "Internet session initialized successfully!" << std::endl;
    InternetCloseHandle(hInternet);
    return 0;
}
```

## References

{% embed url="<https://learn.microsoft.com/ko-kr/windows/win32/api/wininet/nf-wininet-internetopena>" %}
