我需要在我的笔记本电脑上找到已安装打印机的 IP 地址。我在不同的位置和网络之间移动我的笔记本电脑。每个网络都有自己的一组 IP 地址。笔记本电脑为每个位置安装了不同的打印机,所有连接都是无线连接的。
在使用以下代码 (.net 4.0) 时,QueuePort.Name 返回:
WSD-27e3f972-cdc7-459d-b0c1-20e8410fb1db.0032 和
192.168.1.12_1
由于这些是网络打印机,我认为它们必须解析为真实的 IP 地址??
我哪里错了?或者,还有更好的方法?非常感谢任何帮助。
IEnumerable<Printer> GetLocalPrinters()
{
EnumeratedPrintQueueTypes[] enumerationFlags = { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections };
LocalPrintServer printServer = new LocalPrintServer();
var x = printServer.GetPrintQueues(enumerationFlags).Select(y =>
new Printer
{
Fullname = y.FullName,
QueuePortName = y.QueuePort.Name,
Location = y.Location
})
.OrderBy( z => z.QueuePortName);
return x;
}