Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Discovering all devices connected to my network

NitishsantpurNitishsantpur Member ✭✭✭

Hi..
I want to create an app where I need to find devices connected to my wifi network using xamarin form

Best Answer

  • NitishsantpurNitishsantpur Member ✭✭✭
    Accepted Answer

    yes that worked for me sry for late reply
    thankyou

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    For this feature, try use InetAddress.GetByAddress command to get the ip address of the device.

    WifiManager wifiManager = (WifiManager)Android.App.Application.Context.GetSystemService(Context.WifiService);
    string wifi_Ip = IntToInetAddress(wifiManager.DhcpInfo.ServerAddress).ToString().Substring(1);
    
    public InetAddress getIPv4Address(int hostAddress)
    {
        byte[] addressBytes = {(byte) (0xff & hostAddress),
                (byte) (0xff & (hostAddress >> 8)),
                (byte) (0xff & (hostAddress >> 16)),
                (byte) (0xff & (hostAddress >> 24))};
    
        try
        {
            return InetAddress.GetByAddress(addressBytes);
        }
        catch (UnknownHostException ex)
        {
            throw new Java.Lang.AssertionError();
        }
    }
    

    Similar issue:
    https://forums.xamarin.com/discussion/150000/xamarin-android-get-the-ip-address-of-the-hotspot

  • NitishsantpurNitishsantpur Member ✭✭✭

    Thanks for your reply
    Could you please elaborate as in where do I need to use this code and do I need install nuget package as I just have knowledge of basics

  • NitishsantpurNitishsantpur Member ✭✭✭

    I used this and got error

    er.PNG 13.3K
  • JarvanJarvan Member, Xamarin Team Xamurai

    For the function, you need to achieve on each platform. The function code is from native android library, try to use the code on android platform and call the method in pcl with DependencyService.

  • NitishsantpurNitishsantpur Member ✭✭✭
    thanks will try
  • JarvanJarvan Member, Xamarin Team Xamurai

    Waiting for your update.

  • NitishsantpurNitishsantpur Member ✭✭✭
    Accepted Answer

    yes that worked for me sry for late reply
    thankyou

Sign In or Register to comment.