Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4101800
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:44:39+00:00 2026-05-20T20:44:39+00:00

How can I get gateway and subnet mask details in Android?

  • 0

How can I get gateway and subnet mask details in Android?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:44:39+00:00Added an answer on May 20, 2026 at 8:44 pm

    I have found a class called DhcpInfo within the android.net package. It has some public variables that stores the values of current Network parameters. But the problem is they return the value in integer converted from 8Bit shifted binary.

    Sample Image Describing thee Scenario:

    enter image description here

    ****Here is a sample code:**

    **java file:****

    package com.schogini.dhcp;
    
    import android.app.Activity;
    import android.content.Context;
    import android.os.Bundle;
    import android.widget.TextView;
    import android.net.*;
    import android.net.wifi.WifiManager;
    
    public class dhcpInfo extends Activity {
        public String   s_dns1 ;
        public String   s_dns2;     
        public String   s_gateway;  
        public String   s_ipAddress;    
        public String   s_leaseDuration;    
        public String   s_netmask;  
        public String   s_serverAddress;
        TextView info;
        DhcpInfo d;
        WifiManager wifii;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            wifii= (WifiManager) getSystemService(Context.WIFI_SERVICE);
            d=wifii.getDhcpInfo();
    
            s_dns1="DNS 1: "+String.valueOf(d.dns1);
            s_dns2="DNS 2: "+String.valueOf(d.dns2);    
            s_gateway="Default Gateway: "+String.valueOf(d.gateway);    
            s_ipAddress="IP Address: "+String.valueOf(d.ipAddress); 
            s_leaseDuration="Lease Time: "+String.valueOf(d.leaseDuration);     
            s_netmask="Subnet Mask: "+String.valueOf(d.netmask);    
            s_serverAddress="Server IP: "+String.valueOf(d.serverAddress);
    
            //dispaly them
            info= (TextView) findViewById(R.id.infolbl);
            info.setText("Network Info\n"+s_dns1+"\n"+s_dns2+"\n"+s_gateway+"\n"+s_ipAddress+"\n"+s_leaseDuration+"\n"+s_netmask+"\n"+s_serverAddress);
        }
    }
    

    xml Coding:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.schogini.dhcp"
          android:versionCode="1"
          android:versionName="1.0">
        <uses-sdk android:minSdkVersion="4" />
    
        <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".dhcpInfo"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />  
    </manifest>
    

    I tried converting the integer value to its equivalent but i couldn’t. If you do so you can post back.. Bye..

    UPDATE: Some how managed to convert the IP to v4 Format from the integer form
    Conversion to IPv4 Format:

    public String intToIp(int i) {
    
       return ((i >> 24 ) & 0xFF ) + "." +
                   ((i >> 16 ) & 0xFF) + "." +
                   ((i >> 8 ) & 0xFF) + "." +
                   ( i & 0xFF) ;
    }
    

    IMAGE Courtesy: http://www.bennadel.com/blog/1830-Converting-IP-Addresses-To-And-From-Integer-Values-With-ColdFusion.htm

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I determine the IP of my router/gateway in Java? I can get
I can get easily see what projects and dlls a single project references from
I can get both System.Net.Mail and System.Web.Mail to work with GMail, but I can't
Logging can get complicated, quickly. Considering that you have some code, how do you
I can get the executable location from the process, how do I get the
I can get simple examples to work fine as long as there's no master
I can get the element like this $(#txtEmail) but I'm not sure how to
I can get a list of running threads from Process.GetCurrentProcess().Threads, but I need to
I CAN get the associated icon just fine, and draw it accordingly, however, I
I know I can get the public static members of a class by doing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.