Skip to content

[multicast_dns] get IP of mdns SRV target #139002

@guyluz11

Description

@guyluz11

Is there an existing issue for this?

Use case

Related issues
#75585
#53477

I am trying to find the IP of SRV target.

Examples of srv:
eWeLink_10013abc14.local
HPC0180319938E.local
MiWiFi-RM1800-srv.local

I have tried:

  • await InternetAddress.lookup(mdnsName);

import 'package:multicast_dns/multicast_dns.dart';

main() async {
  final MDnsClient client = MDnsClient();
  await client.start();


  await for (final IPAddressResourceRecord ip
  in client.lookup<IPAddressResourceRecord>(
      ResourceRecordQuery.addressIPv4(mdnsName))) {
    print('IP: ${ip.address.toString()}');
  }
  
  client.stop();
}

Using Linux avahi-utils I can find it

$ avahi-resolve-host-name eWeLink_10013abc14.local
eWeLink_10013abc14.local        192.168.31.220

If I can know the serviceType (which I don't) I can use this

String serviceType = '_ewelink._tcp';
String mdnsName = 'eWeLink_10013abc14.local';

final MDnsClient client = MDnsClient();
await client.start();

await for (final PtrResourceRecord ptr in client.lookup<PtrResourceRecord>(
    ResourceRecordQuery.serverPointer(serviceType))) {
  print('PTR: ${ptr.toString()}');

  await for (final IPAddressResourceRecord ip
      in client.lookup<IPAddressResourceRecord>(
          ResourceRecordQuery.addressIPv4(mdnsName))) {
    print('IP: ${ip.address.toString()}');
  }
}
client.stop();

Proposal

Add a new function that can find SRV target IP or to what serviceType it belongs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterp: multicast_dnsThe mdns packagepackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions