mhs
mhs

Reputation: 1042

Get host name by IP address

I tried to get the host name by IP address as bellow.

IPHostEntry entry = Dns.GetHostEntry(ipAddress);
string hostName = entry.HostName;

But for printer devices. this gives SocketException says "No such host is known".

Then I tried with this Ip scanner. It has shown a host name properly (And it is java).

Is there any other way to get host name in C#?

Upvotes: 0

Views: 1908

Answers (1)

too_cool
too_cool

Reputation: 1194

YOu can try this way

Using System.Printing

 var pri = new PrintServer();
            var queues = pri.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });
            foreach (var queue in queues)
            {
                string printerName = queue.Name;
                string printerPort = queue.QueuePort.Name;
             }

Upvotes: 1

Related Questions