Skip to content

Integrating the NetGuard SDK

The NetGuard SDK supports common client operating systems. This page provides all integration methods.

Download the SDK

  • Developers need to Click Here to download the NetGuard SDK.
  • Before integration, obtain your unique AppID and AppKey from the Dashboard.
  • Integrate the NetGuard SDK into Your Client App as needed.

Integration Methods

Microsoft Windows

The Windows version of the NetGuard SDK includes Shield.exe and libshield.dll. The libshield.dll file exports a function named _Init, which follows the C calling convention (__cdecl). Developers can integrate using one of the following methods:

Zero-Code

This method is suitable for developers with limited programming knowledge. Simply create a configuration file, place it along with Shield.exe and libshield.dll, and then run Shield.exe. The configuration file must be named Shield.ini and should contain the following:

ini
[Shield]
AppID = DEVELOPEMENT_APP_ID
; Replace DEVELOPEMENT_APP_ID with your own AppID

Dynamic Library

This method is suitable for developers with a Windows programming background. If you want to ensure that the NetGuard is initialized successfully before running other business logic, this method is recommended. The following code demonstrates how to integrate the SDK in C/C++:

c
/* It is recommended to load this dynamic library in a separate process.
 * Loading it directly into the App process might cause the App to crash
 * or fail to connect to the server
 */

// 1. Declare the function from the SDK
extern "C" {
    typedef int (*InitFunc)(char *, char *);
}

// 2. Load the dynamic library at the appropriate time and initialize it
HMODULE hMod = LoadLibrary("libshield.dll");
if (!hMod)
    return; // Failed to find libshield.dll
InitFunc init = (InitFunc)GetProcAddress(hMod, "Init");
if (!init)
    return; // Failed to find Init function
if (!init(NULL, "DEVELOPEMENT_APP_ID"))  // Replace with your own AppID
    return; // Initialization failed
// Execution continues here if initialization is successful

Google Android

The Android version of the NetGuard SDK comes as a single AAR file. Place this AAR file in the libs directory of your main app project (typically app/libs).

  1. Check and Add the Following to Your App-Level build.gradle
groovy
android {
    sourceSets.main {
        jniLibs.srcDirs = ['libs']
    }
}
dependencies {
    implementation files('libs/libshield.aar')
}
  1. Initialize in the First Activity or Application Class
java
// A return value of true indicates successful initialization
bool bInit = Shield.Init(null, "DEVELOPEMENT_APP_ID"); // Replace with your own AppID

Apple iOS/iPadOS

The iOS version of the NetGuard SDK also supports iPadOS and includes the following two files:

  • Header file: Shield.h
  • Static library: libshield.a

The following code demonstrates how to load and initialize the NetGuard SDK in Objective-C:

objective-c
// 1. First, add libshield.a to your iOS project, otherwise, the build will fail.

// 2. Include the header file
#import "Shield.h"

// 3. Initialize at a appropriate time; a return value of true indicates success
Shield *s = [Shield getInstance];
BOOL bInit = [s Init:nil key:@"DEVELOPEMENT_APP_ID"]; // Replace with your own AppID

Obtain the Client's Real IP Address

Under normal circumstances, the origin server can only obtain the IP address of the Persistence Server, not the client’s IP address.

Please Click Here to download the appropriate IP plugin and install it on the origin server to obtain the client’s real IP address.

Please Note

  • If the origin server is running Windows, the App services must be restarted after installing the plugin.
  • If the origin server is running Linux, the plugin will take effect immediately after compilation and installation.
  • Only developers enrolled in the Shared Defense Plan can obtain the client's real IP address.

Next Steps

  • Log in to the Dashboard and correctly add forwarding rules as needed.
  • Update the existing code to connect to the local loopback IP address instead of the original TCP server.
  • Mobile Apps use the loopback IP address 127.0.0.1, while PC devices need to obtain the loopback IP address from the Dashboard.
  • If you encounter other issues after integrating the NetGuard SDK, please refer to Frequently Asked Questions.

Copyright © 2006-2025 NetGuard