2

I have 3 cameras whose MAC and IP addresses are unknown to me, and I want to connect to them.

I've connected them to my computer with a UTP cable. Now what I have to do is to find their IP addresses in order to establish a connection. In the camera's API, it states that you can use TCP/IP to get video stream from the camera and to use mDNS to find their IP addresses.

How can I find the IP addresses in c#?

(NOTE: no router in need and "arp -a" command did not work)

dsolimano
  • 8,870
  • 3
  • 48
  • 63
  • 1
    Sounds like you need an mDNS tutorial in C#. I'm not too familiar with the technology, but http://stackoverflow.com/a/210520/58074 looks like a promising start. – dsolimano Apr 29 '12 at 06:27
  • What kind of cameras are they? How can you connect them all to your computer via UTP cable without needing a router? – Ove Apr 29 '12 at 06:29
  • hi Ove, thx for helping. they used kind of service uses mdns in order to find ip, im attaching the camera interface to my application and i have to connect to camera too. no router required, when u just connect the camera Zeroconf service discovery find cameras. –  Apr 29 '12 at 06:36

2 Answers2

2

Sending this mDNS packet seems to work for my application which has a Raspberry Pi. I think the IP/ports are specific to ZeroConf/Bonjour, which seems to be widely used so it may work for those cameras.

public void sendDiscoveryQuery(string local_dhcp_ip_address)
{
    // multicast UDP-based mDNS-packet for discovering IP addresses

    System.Net.Sockets.Socket socket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp);

    socket.Bind(new IPEndPoint(IPAddress.Parse(local_dhcp_ip_address), 52634));
    IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("224.0.0.251"), 5353);

    List<byte> bytes = new List<byte>();

    bytes.AddRange(new byte[] { 0x0, 0x0 });  // transaction id (ignored)
    bytes.AddRange(new byte[] { 0x1, 0x0 });  // standard query
    bytes.AddRange(new byte[] { 0x0, 0x1 });  // questions
    bytes.AddRange(new byte[] { 0x0, 0x0 });  // answer RRs
    bytes.AddRange(new byte[] { 0x0, 0x0 });  // authority RRs
    bytes.AddRange(new byte[] { 0x0, 0x0 });  // additional RRs
    bytes.AddRange(new byte[] { 0x05, 0x5f, 0x68, 0x74, 0x74, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x0c, 0x00, 0x01 });  // _http._tcp.local: type PTR, class IN, "QM" question

    socket.SendTo(bytes.ToArray(), endpoint);
}

The 'local_dhcp_ip_address' is the ip address of your computer's nic. Below is a wireshark trace for this interaction. The device responds directly to your computer.

enter image description here

At this point ARP -a should work. You can also use GetIpNetTable.

DAG
  • 867
  • 10
  • 16
0

On some devices the MAC-Address is printed on a lable, maybe on the backside. As far as my understandig goes, they need to be in the arp cache at least once. But this cache only stores 5 (?) entries, so you may have to refresh it, or clear it before you connect the devices or run the config tool.

sschrass
  • 7,014
  • 6
  • 43
  • 62