/hnap-client

Home Network Administration Protocol (HNAP) Client Java Library

Primary LanguageJava

HNAP Client

Build Status codecov.io Codacy Badge

Java Library for interacting with devices using the Home Network Administration Protocol (HNAP).

Usage

    public static void main(String[] args) {
        try {
            final String host = "192.168.1.11"; // The HNAP device's host or IP address
            final String username = "admin"; // Username is normally 'admin'
            final String password = "***"; // Your device password goes here

            // Create HnapClient
            final ClientBuilder clientBuilder = new ClientBuilder();
            final HnapClientI client = clientBuilder.createHnapClient(host, username, password);

            // Discover is part of the HNAP protocol - which is a simple "GET" to HNAP1 path
            // This should tell you the devices capabilities
            // Some devices I tried returned a blank response to this, so don't be too put of if this part didn't work
            final DeviceSettingsI results = client.discover();
            System.out.println(results.toString());


            // Perform a login request (which is a couple of requests) so we can perform requests needing authentication
            final HnapSessionI session = client.login();
            // Return a mixed type map because most responses are basically JSON style structures
            final Map<String, Object> isDeviceReady = client.request(session, "GetDeviceSettings", new LinkedHashMap<>());
            System.out.println(isDeviceReady);
        }
        catch (MalformedURLException | HnapClientException ex) {
            Logger.getLogger(BasicHttpClient.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

Installation

This library isn't currently available in standard repositories, however it can be used via https://jitpack.io/.

The Maven setup is:

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>
        ...
	<dependency>
	    <groupId>com.github.jbuncle</groupId>
	    <artifactId>hnap-client</artifactId>
	    <version>master</version>
	</dependency>