【问题标题】:Finding the closest printer to the client on the network在网络上查找离客户端最近的打印机
【发布时间】:2016-04-11 20:43:43
【问题描述】:

我正在开发一个从文本文件加载一组打印机的应用程序:

 protected void LoadPrinterList()
    {

        string CSVFilePathName = System.Configuration.ConfigurationManager.AppSettings["FilePath"];
        string[] Lines = File.ReadAllLines(CSVFilePathName);
        string[] Fields;
        Fields = Lines[0].Split(new char[] { ',' });
        int Cols = Fields.GetLength(0);
        DataTable dt = new DataTable();
        //1st row must be column names; force lower case to ensure matching later on.
        for (int i = 0; i < Cols; i++)
            dt.Columns.Add(Fields[i].ToLower(), typeof(string));
        dt.Columns.Add("nameanddescription", typeof(string), "name +'-'+ description");
        dt.Columns.Add("ipandconnectionstring", typeof(string), "ip +'-'+ ConncetionStringID");
        DataRow Row;
        for (int i = 1; i < Lines.GetLength(0); i++)
        {
            Fields = Lines[i].Split(new char[] { ',' });
            Row = dt.NewRow();
            for (int f = 0; f < Cols; f++)
                Row[f] = Fields[f];
            dt.Rows.Add(Row);
        }

        string hostname = Request.UserHostName.Substring(0, 3);
        string[] name = Printerlist.SelectedValue.Split('-');
        //string plant = name[0].ToString();
        //string plantvalue = plant.Substring(0, 3);
        //if(hostname == plantvalue)
        //{
        Printerlist.DataTextField = "nameanddescription";
        Printerlist.DataValueField = "ipandconnectionstring";
        //}
        Printerlist.DataSource = dt;
        Printerlist.DataBind();


    }

问题是这些打印机大部分都在工厂里,我需要找到离客户最近的标签打印机,我可以获得客户信息:

public static string DetermineCompName(string IP)
    {
        IPAddress myIP = IPAddress.Parse(IP);
        IPHostEntry GetIPHost = Dns.GetHostEntry(myIP);
        List<string> compName = GetIPHost.HostName.ToString().Split('.').ToList();
        return compName.First();
    }

string IP = Request.UserHostName;
string compName = CompNameHelper.DetermineCompName(IP);

我还拥有每台打印机的 IP 地址,因为我使用 IP 地址进行打印。我的问题是如何根据客户端的IP和打印机的IP找到最接近的?

是否有任何替代解决方法?我在网上看了很多,但找不到足够的信息。

【问题讨论】:

  • 简单的答案 - 你不能,通常距离和 IP 地址之间没有关系,尤其是在内部 LAN 中
  • 我能想到的唯一可能的事情是对每个 ping 几次,然后取所有 ping 的平均值,然后无论哪一个是最低的,你可以猜出最接近的一个,但可能几乎每次都错了..
  • 我怀疑会有办法做到这一点superuser.com/questions/327417/…
  • 我想您可以将客户端和打印机的静态 IP 地址与坐标相关联,并编写一个脚本来确定客户端和所有打印机之间的距离,然后选择最近的 IP。然而,维护所有这些坐标会很痛苦。

标签: c# asp.net printing client zebra-printers


【解决方案1】:

在公司网络中,交换机可能被连接起来以将设备与具有已知位置的端口相关联。我已经支持了几十个网络,但从未见过你要求的细节。不过理论上你可以,如果网络支持可以保持更新记录哪些交换机端口去哪些墙端口。通常打印机只会在一个级别的几个地方,并且每个级别都有一个子网。许多网络的名称或位置描述中都有提示。

或者,如果这不仅仅是白日梦而且你真的需要它,我会考虑一个单独的位置感知系统,例如 rfid 资产跟踪,甚至让所有打印机都使用 wifi。企业 wifi 阵列可以估计设备位置(我知道 Xirrus 可以做到这一点,并且对于最近的打印机来说效果很好)。编辑:然后要获取设备的位置,您可以在 wifi 阵列上使用 SNMP 查询。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-07
    相关资源
    最近更新 更多