Ipop.StaticDns.NameLookUp C# (CSharp) Method

NameLookUp() public method

Called during LookUp to perfrom a translation from IP to hostname.
public NameLookUp ( String ip ) : String
ip String The IP to look up.
return String
    public override String NameLookUp(String ip)
    {
      if(!InRange(ip)) {
        throw new Exception("Unable to resolve");
      }

      String res = null;
      if(InRange(ip)) {
        res = "C";
        byte [] ipb = Utils.StringToBytes(ip, '.');
        for(int i = 1; i < 4; i++) {
          if(ipb[i] < 10) {
            res += "00";
          }
          else if(ipb[i] < 100) {
            res += "0";
          }
          res += ipb[i];
        }
        res += "." + DomainName;
      }
      return res;
    }
  }

Usage Example

Example #1
0
        public void Test()
        {
            StaticDns dns = new StaticDns(
                MemBlock.Reference(Utils.StringToBytes("10.250.0.0", '.')),
                MemBlock.Reference(Utils.StringToBytes("255.255.0.0", '.')),
                string.Empty, false);

            Assert.AreEqual(dns.NameLookUp("10.250.1.1"), "C250001001.ipop", "NameLookUp Dns set in range.");

            try {
                Assert.AreEqual(dns.NameLookUp("10.251.1.1"), null, "NameLookUp Dns set out of range.");
            } catch { }

            Assert.AreEqual(dns.AddressLookUp("C250001001.ipop"), "10.250.1.1", "AddressLookUp Dns set.");

            try {
                Assert.AreEqual(dns.AddressLookUp("C250001001.blaha"), null, "AddressLookUp Dns set bad dns name: blaha.");
            } catch { }

            try {
                Assert.AreEqual(dns.AddressLookUp("C250001001.blah"), null, "AddressLookUp Dns set bad dns name: blah.");
            } catch { }

            dns = new StaticDns(
                MemBlock.Reference(Utils.StringToBytes("10.251.0.0", '.')),
                MemBlock.Reference(Utils.StringToBytes("255.255.0.0", '.')),
                string.Empty, false);

            try {
                Assert.AreEqual(dns.NameLookUp("10.250.1.1"), null, "NameLookUp Dns changed out of range.");
            } catch { }

            Assert.AreEqual(dns.NameLookUp("10.251.1.1"), "C251001001.ipop", "NameLookUp Dns changed in range.");
        }
All Usage Examples Of Ipop.StaticDns::NameLookUp