Changing default IP TTL

In this page, usage of SetIpTTL() is shown. The default IP TTL of the windows computer can be changed by using SetIpTTL().

Sample code

The following sample code changes the default IP TTL value. Please note that, SetIpTTL() will change the default IP TTL value for every data transmission. And the change will remain even after the SetIpTTL() calling process ends.


#include <stdio.h>

#include <winsock2.h>
#include <iphlpapi.h>

int
main()
{
 UINT defaultTtl;
 DWORD dw;

 defaultTtl = 64;
 dw = SetIpTTL(defaultTtl);
 if (dw == NO_ERROR) {
   printf("Default TTL set to %d\n", defaultTtl);
 } else {
   printf("SetIpTTL failed\n");
 }

 return 0;
}

To know the current default TTL, you can use GetIpStatistics().

The sample code here uses SetIpTTL() to change the default IP TTL value. You can also use SetIpStatistics() to change the default IP TTL value.

Sample code output

The sample will output an message like the following.


C:> a.exe
Default TTL set to 64

  

Copyright (C) GeekPage.JP. All rights reserved.