Here you can find the source of int2InetAddress(int val)
Parameter | Description |
---|---|
val | int representation of IPv4 address |
public static final InetAddress int2InetAddress(int val)
//package com.java2s; /**/*ww w . j a va 2s.c om*/ * Copyright (c) 2014-2016 openHAB UG (haftungsbeschraenkt) and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ import java.net.InetAddress; import java.net.UnknownHostException; public class Main { /** * Converts 32 bits int to IPv4 <tt>InetAddress</tt>. * * @param val int representation of IPv4 address * @return the address object */ public static final InetAddress int2InetAddress(int val) { byte[] value = { (byte) ((val & 0xFF000000) >>> 24), (byte) ((val & 0X00FF0000) >>> 16), (byte) ((val & 0x0000FF00) >>> 8), (byte) ((val & 0x000000FF)) }; try { return InetAddress.getByAddress(value); } catch (UnknownHostException e) { return null; } } }