Ejemplo n.º 1
0
        public JsonResult CheckIpAddress(string ipAddress, string networkAddress, string networkMask)
        {
            var networkAddressBytes = IpAddressHelper.ConvertStringToIpAddress(networkAddress);
            var maskAddress         = IpAddressHelper.ConvertStringToIpAddress(networkMask);
            var currentAddress      = IpAddressHelper.ConvertStringToIpAddress(ipAddress);

            var startIpBytes = new byte[networkAddressBytes.Length];
            var endIpBytes   = new byte[networkAddressBytes.Length];

            for (var i = 0; i < networkAddressBytes.Length; i++)
            {
                startIpBytes[i] = (byte)(networkAddressBytes[i] & maskAddress[i]);
                endIpBytes[i]   = (byte)(networkAddressBytes[i] | ~maskAddress[i]);
            }

            var result = true;

            for (var i = 0; i < networkAddressBytes.Length; i++)
            {
                if (!(currentAddress[i] >= startIpBytes[i] && currentAddress[i] <= endIpBytes[i]))
                {
                    result = false;
                }
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(ComputerEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Error"));
            }

            var entity = new Computer
            {
                ComputerId     = model.Id,
                RoomNumber     = Convert.ToInt32(model.RoomNumber),
                Name           = model.Name,
                IpAddress      = IpAddressHelper.ConvertStringToIpAddress(model.IpAddress),
                NetworkAddress = IpAddressHelper.ConvertStringToIpAddress(model.NetworkAddress),
                SubnetAddress  = IpAddressHelper.ConvertStringToIpAddress(model.NetworkMask)
            };

            if (entity.ComputerId != 0)
            {
                _computerService.UpdateComputer(entity);
                _historyService.Insert(new History
                {
                    Email    = AuthHelper.GetUser(HttpContext).Email,
                    Action   = Action.Update,
                    DateTime = DateTime.Now,
                    Entity   = EntityEnum.Computer
                });
            }
            else
            {
                _computerService.CreateComputer(entity);
                _historyService.Insert(new History
                {
                    Email    = AuthHelper.GetUser(HttpContext).Email,
                    Action   = Action.Create,
                    DateTime = DateTime.Now,
                    Entity   = EntityEnum.Computer
                });
            }

            return(RedirectToAction("Index"));
        }