Home > Undocumented WinAPI > Changing IP Address of a machine!

Changing IP Address of a machine!

To change ip address of a machine use SetAdapterIpAddress. It’s an undocumented API found in iphlpapi.dll.

Function signature is as follows…

DWORD SetAdapterIpAddress( char *pszAdapGUID,
                           DWORD dwDHCP,
                           DWORD dwIP,
                           DWORD dwMask,
                           DWORD dwGateway );

Look here for a demo, it’s in Russian but code is in english 😉

  1. June 25, 2012 at 10:24 pm

    here is a complete example compiled successfully with MinGW:

    #include
    #include
    #include
    #include

    typedef DWORD (WINAPI *_SetAdapterIpAddress )( char *szAdapterGUID,
    DWORD dwDHCP,
    DWORD dwIP,
    DWORD dwMask,
    DWORD dwGateway );

    int main()
    {
    HINSTANCE lib = (HINSTANCE) LoadLibrary("iphlpapi.dll");
    _SetAdapterIpAddress SetAdapterIpAddress = (_SetAdapterIpAddress) GetProcAddress(lib, "SetAdapterIpAddress");

    PWSTR pszGUID = NULL;
    char szGUID[] = "{9FC8CB51-DCB1-4113-99AD-AB79D65867AA}";
    DWORD dwSize = 0;
    WideCharToMultiByte(CP_ACP, 0, pszGUID, -1, szGUID, sizeof(szGUID), NULL, NULL);

    SetAdapterIpAddress(szGUID,
    0,
    inet_addr("192.168.1.10"),
    inet_addr("255.255.255.0"),
    inet_addr("192.168.1.1"));

    return 0;
    }

    Compile command:
    g++ -o SetAdapter SetAdapter.cpp -lwsock32 -liphlpapi
    You should link with iphlpapi and wsock32.

  1. No trackbacks yet.

Leave a comment