Esempio n. 1
0
        private async void BtnRequest_Click(object sender, EventArgs e)
        {
            treeResult.Nodes.Clear();
            SetControlsState(false);
            IPResult result = null;

            if (ckAsync.Checked)
            {
                if (cmbFields.SelectedIndex != 0)
                {
                    string txt = await IPInfo.GetAsync((IPInfoKey)cmbFields.SelectedItem, GetValidIP(), txtToken.Text);

                    MessageBox.Show(txt);
                    SetControlsState(true);
                    return;
                }
                result = await IPInfo.GetAsync(GetValidIP(), txtToken.Text);
            }
            else
            {
                if (cmbFields.SelectedIndex != 0)
                {
                    MessageBox.Show(IPInfo.Get((IPInfoKey)cmbFields.SelectedItem, GetValidIP(), txtToken.Text));
                    SetControlsState(true);
                    return;
                }
                result = IPInfo.Get(GetValidIP(), txtToken.Text);
            }
            PopulateTree(result);
        }
Esempio n. 2
0
        private void GetIpInfo()
        {
            IPInfo IP = IPInfo.GetIPInfo();

            byte[] Bytes = IP.IPAddress.GetAddressBytes();
            ip_a.Value = Bytes[0].ToString();
            ip_b.Value = Bytes[1].ToString();
            ip_c.Value = Bytes[2].ToString();
            ip_d.Value = Bytes[3].ToString();

            Bytes       = IP.SubNet.GetAddressBytes();
            net_a.Value = Bytes[0].ToString();
            net_b.Value = Bytes[1].ToString();
            net_c.Value = Bytes[2].ToString();
            net_d.Value = Bytes[3].ToString();

            Bytes      = IP.Gateway.GetAddressBytes();
            gw_a.Value = Bytes[0].ToString();
            gw_b.Value = Bytes[1].ToString();
            gw_c.Value = Bytes[2].ToString();
            gw_d.Value = Bytes[3].ToString();

            //ip_info.Value = IP.Shell.Result;

            ip_info.InnerText = IP.Shell.Result;
        }
            public static IPInfo FromString(string e)
            {

                string[] x = IArray.Split(e, ".");

                if (x.Length != 4)
                {
                    Native.Break("invalid IPv4, environment broken?");
                }


                IPInfo n = new IPInfo();

                n.Text = e;

                n.Subnet = 0;
                n.Address = 0;

                for (int i = 0; i < 4; i++)
                {
                    n.Bytes[i] = byte.Parse(x[i]);

                    //Native.Message("#" + i, n.Bytes[i] + "");

                    if (i < 3)
                        n.Subnet += n.Bytes[i] << (24 - i * 8);
                }

                n.Address = n.Subnet + n.Bytes[3];

                //Native.Message("subnet", Native.API.dechex(n.Subnet) + " - " + n.Text);

                return n;
            }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a IP address to checkup ( leave blank to use your own IP ): ");
            string input = Console.ReadLine();

            IPAddress ip = null;

            IPInfo info = (input.Length > 1 && IPAddress.TryParse(input, out ip)) ? IPInfo.Get(input) : IPInfo.Get();

            if (info != null)
            {
                Console.WriteLine($"IP: {info.IP}");
                Console.WriteLine($"Country: {info.Country}");
                Console.WriteLine($"Region: {info.Region}");
                Console.WriteLine($"City: {info.City}");
                Console.WriteLine($"Postal: {info.Postal}");
                Console.WriteLine($"Location: {info.Location}");
                Console.WriteLine($"Organisation: {info.Organitation}");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("A error occured while trying to get the informations. Press any key to exit");
                Console.ReadLine();
            }
        }
Esempio n. 5
0
 public void FetchIPData(bool focus)
 {
     if (vIPData == null || focus)
     {
         vIPData = IPInfo.Fetch(vHostIP);
     }
 }
            public static IPInfo FromString(string e)
            {
                string[] x = IArray.Split(e, ".");

                if (x.Length != 4)
                {
                    Native.Break("invalid IPv4, environment broken?");
                }


                IPInfo n = new IPInfo();

                n.Text = e;

                n.Subnet  = 0;
                n.Address = 0;

                for (int i = 0; i < 4; i++)
                {
                    n.Bytes[i] = byte.Parse(x[i]);

                    //Native.Message("#" + i, n.Bytes[i] + "");

                    if (i < 3)
                    {
                        n.Subnet += n.Bytes[i] << (24 - i * 8);
                    }
                }

                n.Address = n.Subnet + n.Bytes[3];

                //Native.Message("subnet", Native.API.dechex(n.Subnet) + " - " + n.Text);

                return(n);
            }
Esempio n. 7
0
        public IPInfo GetInfo(string ipAddress)
        {
            var    fault   = new SoapFault();
            string message = "";
            //Match pattern for IP address
            string Pattern = @"^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$";
            //Regular Expression object
            Regex check = new Regex(Pattern);

            //check to make sure an ip address was provided
            if (string.IsNullOrEmpty(ipAddress))
            {
                message = "Enpty input ---> please provide an ip address";
                fault.myThrow(message);
            }
            else if (!check.IsMatch(ipAddress, 0))
            {
                message = "Ip format error ---> your ip is in wrong format";
                fault.myThrow(message);
            }

            IPInfo info = new IPInfo();

            GEO.P2GeoSoapClient geo = new GEO.P2GeoSoapClient("IP2GeoSoap");
            var ipInfo = geo.ResolveIP(ipAddress, "0");

            info.City          = ipInfo.City;
            info.Country       = ipInfo.Country;
            info.Latitude      = Convert.ToDecimal(ipInfo.Latitude);
            info.Longitude     = Convert.ToDecimal(ipInfo.Longitude);
            info.Organization  = ipInfo.Organization;
            info.StateProvince = ipInfo.StateProvince;

            return(info);
        }
Esempio n. 8
0
        public override void GridInsertRow <T>(
            SourceGrid.Grid grid,
            T item,
            Func <T, Color, Base.Grid.GridCellController> newCellController = null,
            int Index = -1)
        {
            int index = Index < 0 ? grid.RowsCount : Index;

            grid.Rows.Insert(index);
            grid.Rows[index].Tag = item;

            Type itemType = item.GetType();

            if (itemType == typeof(IPInfo))
            {
                IPInfo ipInfo = item as IPInfo;
                SourceGrid.Cells.Controllers.IController CellController = newCellController(item, Color.LightBlue);
                grid[index, 0] = newCell(ipInfo, ipInfo.IPAddressStr, CellController);
                grid[index, 1] = newCell(ipInfo, ipInfo.RoundtripTime, CellController);
                grid[index, 2] = newCell(ipInfo, ipInfo.HostName, CellController);
                grid[index, 3] = newCell(ipInfo, ipInfo.HostMac, CellController);
                Console.WriteLine(ipInfo.IPAddressStr);
                return;
            }

            {
                SourceGrid.Cells.Controllers.IController CellController = newCellController(item, Color.LightBlue);
                grid[index, 0] = newCell(item, item, CellController);
            }
        }
Esempio n. 9
0
        //解析指定IP的详细信息,包括开放工作端口等
        private void  AnalysisDetailMessage(string IP, string MAC, byte devType)
        {
            IPInfo ipinfo = new IPInfo(IP, MAC);

            try
            {
                uint   res   = ZN_GetDevInfoUDPbyMACAndIP(MAC, IP, devType);
                byte[] szval = new byte[100];
                if (res != 1)
                {
                    return;
                }
                res = ZN_GetDevConfigUDP("C1_PORT", ref szval[0]);
                if (res == 1)
                {
                    ipinfo._WorkPort = Convert.ToInt32(System.Text.Encoding.ASCII.GetString(szval).Replace("\0", ""));
                }
            }
            catch
            { }
            finally
            {
                m_listScanResult.Add(ipinfo);
                backgroundWorker_scan.ReportProgress(-1, (object)ipinfo);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 创建IP信息对象
        /// </summary>
        /// <param name="IP">IP地址</param>
        /// <param name="SrcPort">源端口</param>
        /// <param name="DestPort">目的端口</param>
        /// <returns>IP信息对象</returns>
        private IPInfo CreateIPInfo(string IP, int SrcPort, int DestPort)
        {
            WebRequest request = WebRequest.Create("http://ip-api.com/line/" + IP + "?fields=49689&lang=zh-CN");
            IPInfo     iPInfo  = new IPInfo
            {
                IP       = IP,
                SrcPort  = SrcPort,
                DestPort = DestPort
            };

            using (WebResponse response = request.GetResponse())
            {
                Stream       s  = response.GetResponseStream();
                StreamReader sr = new StreamReader(s);
                // IP地址数据是否有效
                string str_status = sr.ReadLine();
                if (str_status.Equals("success") == true)
                {
                    // 国家
                    iPInfo.Geo += sr.ReadLine();
                    // 区域
                    iPInfo.Geo += sr.ReadLine();
                    // 城市
                    iPInfo.Geo += sr.ReadLine();
                    // 网络供应商
                    iPInfo.ISP = sr.ReadLine();
                }
            }
            return(iPInfo);
        }
Esempio n. 11
0
        private void fetchBtn_Click(object sender, EventArgs e)
        {
            connected_hosts.Clear();
            List <IPInfo> list = IPInfo.GetIPInfo();

            foreach (IPInfo host in list)
            {
                string mac = host.MacAddress;

                if (host.IPAddress.StartsWith("192.168") && !mac.StartsWith("ff"))
                {
                    if (!connected_hosts.Contains(mac))
                    {
                        connected_hosts.Add(mac);
                    }
                }
            }

            //display btn
            label1.Text = "Connected:\n\n";

            foreach (string fill in connected_hosts)
            {
                label1.Text += fill + "\n";
            }
        }
Esempio n. 12
0
    /// <summary>
    /// Retrieves the IPInfo for the machine on the local network with the specified MAC Address.
    /// </summary>
    /// <param name="macAddress">The MAC Address of the IPInfo to retrieve.</param>
    /// <returns></returns>
    public static IPInfo GetIPInfo(string macAddress)
    {
        var ipinfo = (from ip in IPInfo.GetIPInfo()
                      where ip.MacAddress.ToLowerInvariant() == macAddress.ToLowerInvariant()
                      select ip).FirstOrDefault();

        return(ipinfo);
    }
Esempio n. 13
0
        private void SetIPInfoDisplay(IPInfo ipinfo)
        {
            DisplayName = Device.Name ?? ipinfo.HostName;

            MACAddress = "MAC: " + ipinfo.MacAddress;
            IPAddress  = "IP: " + ipinfo.IPAddress;

            HostName = ipinfo.HostName;
        }
Esempio n. 14
0
        private void GetIpInfo()
        {
            IPInfo IP = IPInfo.GetIPInfo();

            txtIP.Text   = IP.IPAddress.ToString();
            txtNet.Text  = IP.SubNet.ToString();
            txtGw.Text   = IP.Gateway.ToString();
            txtInfo.Text = IP.Shell.Result;
        }
        public string Get(string IP)
        {
            string ip = HandlerIP.ConvertIPToHexString(IP);
            IEnumerable <IPInfo> ipInfo = _IPInfoRepository.GetIP(ip);

            IPInfo res = ipInfo.ElementAt(0);

            return(res.ToString());
        }
Esempio n. 16
0
        public async Task <IPInfo> getinfo(string ip)
        {
            return(await Task <IPInfo> .Factory.StartNew(() =>
            {
                IPInfo info = new IPInfo(ip);

                return info;
            }));
        }
Esempio n. 17
0
 private void backgroundWorker_scan_ProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     if (e.ProgressPercentage == -1)
     {
         IPInfo info = (IPInfo)e.UserState;
         dataGridView_IPSearch.Rows.Add(info._IP, info._MAC, info._WorkPort);
     }
     else
     {
         progressBar1.Value = e.ProgressPercentage;
     }
 }
        private void OnPacketArrival(object sender, CaptureEventArgs e)
        {
            var time      = e.Packet.Timeval.Date;
            var length    = e.Packet.Data.Length;
            var packet    = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
            var udpPacket = packet.Extract <PacketDotNet.UdpPacket>();

            if (udpPacket != null)
            {
                var       ipPacket = (PacketDotNet.IPPacket)udpPacket.ParentPacket;
                IPAddress srcIp    = ipPacket.SourceAddress;
                IPAddress destIp   = ipPacket.DestinationAddress;

                bool   isInbound;
                string serverIp;
                // Verify that one of the addresses equals our capture device IP.
                if (srcIp.ToString().Equals(_captureDeviceInfo.ipv4Address))
                {
                    isInbound = false;
                    serverIp  = destIp.ToString() + " src_port: " + udpPacket.SourcePort + " dest_port: " + udpPacket.DestinationPort;
                }
                else if (destIp.ToString().Equals(_captureDeviceInfo.ipv4Address))
                {
                    isInbound = true;
                    serverIp  = srcIp.ToString() + " src_port: " + udpPacket.DestinationPort + " dest_port: " + udpPacket.SourcePort;
                }
                else
                {
                    // We don't care about these packets.
                    return;
                }
                // Look to see if we have encountered the IP already.
                lock (_addressToInfoLock) {
                    if (!_addressToInfo.ContainsKey(serverIp))
                    {
                        _addressToInfo[serverIp] = new IPInfo(serverIp);
                    }
                    IPInfo info = _addressToInfo[serverIp];

                    // Create the packet.
                    PacketInfo packetInfo = new PacketInfo(time, length);
                    if (isInbound)
                    {
                        info.inboundPackets.Add(packetInfo);
                    }
                    else
                    {
                        info.outboundPackets.Add(packetInfo);
                    }
                }
            }
        }
Esempio n. 19
0
        private void DataLayerLocation_GotData(object sender, DataLayerEventArgs <IPInfo> e)
        {
            IPInfo iPInfo = e.Item;

            Cursor = Cursors.Arrow;

            if (iPInfo == null)
            {
                return;
            }

            textBoxLatitude.Text  = iPInfo.Latitude.ToStringCultureFormatted();
            textBoxLongitude.Text = iPInfo.Longitude.ToStringCultureFormatted();
        }
    private async void MyIPBtn_Click(object sender, RoutedEventArgs e)
    {
        if (await NetworkConnection.IsAvailableAsync())
        {
            var ip = await Global.GetIPInfo("");  // Get IP info

            lat                  = ip.Lat;        // Define
            lon                  = ip.Lon;        // Define
            IPInfoTxt.Text       = ip.ToString(); // Show IP info
            IPTxt.Text           = ip.Query;
            lastIP               = ip.Query;      // Define
            IPRadioBtn.IsChecked = true;
            IPInfo               = ip;            // Set
        }
    }
Esempio n. 21
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            IPInfo = await _context.IPInfo.FirstOrDefaultAsync(m => m.IPID == id);

            if (IPInfo == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Esempio n. 22
0
 private async Task <IPInfo> getIpData(string clipboard)
 {
     return(await Task <IPInfo> .Factory.StartNew(() =>
     {
         IPInfo ipinfo = new IPInfo(clipboard);
         if (null == ipinfo.Data)
         {
             return null;
         }
         else
         {
             previousIp = ipinfo.Data.IPAddress;
             return ipinfo;
         }
     }));
 }
Esempio n. 23
0
        public IPInfo GetInfo(string ipAddress)
        {
            InitLogService("ResolveIP", "ResolveIP.txt");

            LogServiceAccessed();

            StringBuilder b = new StringBuilder();

            b.AppendFormat("IP = {0} @", ipAddress);
            LogServiceError(b.ToString());

            IPInfo    info = new IPInfo();
            IPAddress address;

            if (IPAddress.TryParse(ipAddress, out address))
            {
                var client = new IpGoeLookUp.P2GeoSoapClient();

                IpGoeLookUp.IPInformation geoinfo = null;


                try
                {
                    geoinfo = client.ResolveIP(ipAddress, "0");

                    info.City          = geoinfo.City;
                    info.Country       = geoinfo.Country;
                    info.Latitude      = (decimal)geoinfo.Latitude;
                    info.Longitude     = (decimal)geoinfo.Longitude;
                    info.Organization  = geoinfo.Organization;
                    info.StateProvince = geoinfo.StateProvince;
                }
                catch (Exception ex)
                {
                    info.error = LogServiceError(ex.Message + " Failed to connect to remote service @");
                }
            }
            else
            {
                info.error = LogServiceError("Invalid ip service rejected request @");
            }

            LogServiceDone(info.City + " " + info.Country + "" + info.Latitude.ToString() +
                           " " + info.Longitude.ToString() + " " + info.Organization + " " + info.StateProvince);

            return(info);
        }
Esempio n. 24
0
        /// <summary>
        /// 判断IP、源端口、目的端口是否与最后一条完全一致
        /// </summary>
        /// <param name="IP">IP地址</param>
        /// <param name="SrcPort">源端口</param>
        /// <param name="DestPort">目的端口</param>
        /// <returns></returns>
        private bool NotTheSame(string IP, int SrcPort, int DestPort)
        {
            if (IPList.Count == 0)
            {
                return(true);
            }
            IPInfo LastIP = IPList[IPList.Count - 1];

            if (LastIP.IP.Equals(IP) && LastIP.SrcPort == SrcPort && LastIP.DestPort == DestPort)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 25
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            IPInfo = await _context.IPInfo.FindAsync(id);

            if (IPInfo != null)
            {
                _context.IPInfo.Remove(IPInfo);
                await _context.SaveChangesAsync();
            }

            return(LocalRedirect("~/maint/ItemDetailEdit?id=" + IPInfo.itemID));
        }
Esempio n. 26
0
        public void ipinfoTest()
        {
            var i = new IPInfo();

            Assert.IsTrue(new[] {
                "01101100.10111111.10011000.11100000 108.191.152.224",
                "11100000.00000000.00000000.00000000 224.0.0.0",
                "01100000.00000000.00000000.00000000 96.0.0.0",
                "01100000.00000000.00000000.00000001 96.0.0.1",
                "01111111.11111111.11111111.11111110 127.255.255.254",
                "01111111.11111111.11111111.11111111 127.255.255.255"
            }.SequenceEqual(i.ipinfo("108.191.152.224/3")));
            Assert.IsTrue(new[] {
                "10110000.11001010.01110011.10111001 176.202.115.185",
                "11111111.11111111.10000000.00000000 255.255.128.0",
                "10110000.11001010.00000000.00000000 176.202.0.0",
                "10110000.11001010.00000000.00000001 176.202.0.1",
                "10110000.11001010.01111111.11111110 176.202.127.254",
                "10110000.11001010.01111111.11111111 176.202.127.255"
            }.SequenceEqual(i.ipinfo("176.202.115.185/17")));
            Assert.IsTrue(new[] {
                "01001100.10110010.01000100.00000000 76.178.68.0",
                "11111100.00000000.00000000.00000000 252.0.0.0",
                "01001100.00000000.00000000.00000000 76.0.0.0",
                "01001100.00000000.00000000.00000001 76.0.0.1",
                "01001111.11111111.11111111.11111110 79.255.255.254",
                "01001111.11111111.11111111.11111111 79.255.255.255"
            }.SequenceEqual(i.ipinfo("76.178.68.0/6")));
            Assert.IsTrue(new[] {
                "11101101.00100001.11011101.00110001 237.33.221.49",
                "11100000.00000000.00000000.00000000 224.0.0.0",
                "11100000.00000000.00000000.00000000 224.0.0.0",
                "11100000.00000000.00000000.00000001 224.0.0.1",
                "11111111.11111111.11111111.11111110 255.255.255.254",
                "11111111.11111111.11111111.11111111 255.255.255.255"
            }.SequenceEqual(i.ipinfo("237.33.221.49/3")));
            Assert.IsTrue(new[] {
                "01110001.10100101.11010111.01010111 113.165.215.87",
                "11111000.00000000.00000000.00000000 248.0.0.0",
                "01110000.00000000.00000000.00000000 112.0.0.0",
                "01110000.00000000.00000000.00000001 112.0.0.1",
                "01110111.11111111.11111111.11111110 119.255.255.254",
                "01110111.11111111.11111111.11111111 119.255.255.255"
            }.SequenceEqual(i.ipinfo("113.165.215.87/5")));
        }
        public HostForm(IPInfo IPInfo)
        {
            InitializeComponent();
            ipInfo = IPInfo;
            fill   = new Grid.Fill();

            fill.GridFill(SG_HostOpenPorts, ipInfo.Ports,
                          (PortInfo item, Color color) =>
            {
                return(new Grid.GridCellController(Color.LightBlue));
            },
                          new List <string>()
            {
                "Ports", "Protocol", "isOpen"
            });

            //Fill.GridFill(SG_HostOpenPorts, ipInfo.HostPorts, new GridCellController(ipInfo, Color.LightBlue), new List<string>() { "Ports", "Protocol" });
        }
Esempio n. 28
0
        /// <summary>
        /// Updates all IPs manually. Warns the user if a minute not has passed yet.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The event arguments.</param>
        private void btn_refresh_Click(object sender, EventArgs e)
        {
            // Check if 1 minute has passed
            var passedTime = (TimeSpan.FromMinutes(5) - (DateTime.Now - startTime))
                             .TotalMinutes;

            if (passedTime > 4)
            {
                // Warn the user
                MessageBox.Show("One minute has not been passed yet, do not manually update it too fast/often. This can get your client blocked.");
            }

            // Update all IPs
            IPInfo ipInfo = updateIPs();

            Debug.WriteLine("Refreshed IPv4 with new IP: " + ipInfo.IPv4Address);
            Debug.WriteLine("Refreshed IPv6 with new IP: " + ipInfo.IPv6Address);
        }
Esempio n. 29
0
        private void GetIpInfo(object data)
        {
            var       ipinfoFound = false;
            var       count       = 0;
            const int maxTry      = 10;

            // count is used to only check a certain number of times before giving up
            // This will keep the thread from preventing the app from exiting when the user closes the main window.

            while (!ipinfoFound && count < maxTry)
            {
                try
                {
                    var pd     = data as PeerDeviceViewModel;
                    var ipinfo = IPInfo.GetIPInfo(pd.Peer.MacAddress.Replace(":", "-"));
                    if (ipinfo != null)
                    {
                        Dispatcher.CurrentDispatcher.Invoke((Action) delegate()
                        {
                            SetIPInfoDisplay(ipinfo);
                        });

                        ipinfoFound = true;
                    }
                    else
                    {
                        _backgroundWorker.ReportProgress(maxTry / count * 100);
                        Thread.Sleep(1000);
                    }
                }
                catch { }

                count++;
            }
            if (!ipinfoFound)
            {
                Dispatcher.CurrentDispatcher.Invoke((Action)SetIPNotFound);
            }
            //lock (this)
            //{
            //    if (DataChanged != null)
            //        DataChanged(this, null);
            //}
        }
Esempio n. 30
0
        /**<summary>
         * Must be called after the App.GlobalConfig has been loaded
         * </summary>
         */
        public ServerProfile()
        {
            vHostIP   = "";
            vPort     = 0;
            vEncrypt  = "chacha20-ietf-poly1305";
            vPassword = "";
            vRemarks  = "";

            vPluginEnabled = false;
            vPluginName    = "";
            vPluginOption  = "";

            vFriendlyName = "";
            vTimeout      = App.GlobalConfig != null ? App.GlobalConfig.ConnectionTimeouts : 3;

            vTimeCreated = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            vPing        = 0;
            vIPData      = null;
        }
 public ActionResult Index(string ip)
 {
     Regex regex = new Regex(Resource.Regexs["ip"]);
     IPDetails details = null;
     IPInfo ipInfo = null;
     if (regex.IsMatch(ip))
     {
         ipInfo = IPInfoServices.LoadFirst(i => i.IP == ip);
         if (ipInfo == null)
         {
             ipInfo = IPResult.GetData(ip);
             //IPData ipData = IPResult.GetData(ip);
             //IPInfo ipInfoMapp = Mapper.Map<IPInfo>(ipData);
             ipInfo = IPInfoServices.AddEntity(ipInfo);
         }
     }
     details = Mapper.Map<IPDetails>(ipInfo);
     return View(details);
 }
    /// <summary>
    /// Adds IP address to contact. Called when the "Add IP to contact" button is pressed.
    /// Expects the CreateContact method to be run first.
    /// </summary>
    private bool AddIPAddress()
    {
        // Get dataset of contacts
        string where = "ContactLastName LIKE N'My New Contact%'";
        InfoDataSet<ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, 1, null);

        if (!DataHelper.DataSourceIsEmpty(contacts))
        {
            // Get the contact from dataset
            ContactInfo contact = contacts.First<ContactInfo>();

            // Create new IP address
            IPInfo newIP = new IPInfo()
                               {
                                   IPAddress = "127.0.0.1",
                                   IPOriginalContactID = contact.ContactID,
                                   IPActiveContactID = contact.ContactID
                               };

            // Save the IP info
            IPInfoProvider.SetIPInfo(newIP);

            return true;
        }

        return false;
    }
Esempio n. 33
0
        private void GetIpInfo()
        {
            String Command = "";
            String Arguments = "";
            String Pattern = "";
            txtInfo.Text = "";

            switch (CurrentPlatform)
            {
                case Platform.Windows:
                    Command = "ipconfig";
                    Pattern = @"IPv4.*: (?<ip>.*)\r\n.*: (?<net>.*)\r\n.*: (?<gw>.*)\r\n";
                    break;
                case Platform.Linux:
                    Command = "ifconfig";
                    Arguments = "eth0";
                    Pattern = @"inet\s(?<ip>.*)\snetmask\s(?<net>.*)\sbroadcast\s(?<gw>.*)";
                    break;
                case Platform.MacOSX:
                    Command = "ifconfig";
                    Arguments = "en0";
                    Pattern = @"inet\s(?<ip>.*)\snetmask\s(?<net>.*)\sbroadcast\s(?<gw>.*)";
                    break;
                default:
                    break;
            }

            Process pNet = new Process();
            ProcessStartInfo psi = new ProcessStartInfo(Command);
            psi.Arguments = Arguments;
            psi.RedirectStandardOutput = true;
            psi.UseShellExecute = false;
            psi.CreateNoWindow = true;
            pNet.StartInfo = psi;
            pNet.Start();
            txtInfo.Text += pNet.StandardOutput.ReadToEnd();
            Clipboard.Clear();
            Clipboard.SetText(txtInfo.Text);

            String Input = txtInfo.Text;
            Regex Ex = new Regex(Pattern);
            Match M = Ex.Match(Input);
            if (M.Success)
            {
                IPInfo Ip = new IPInfo(M.Groups["ip"].Value, M.Groups["net"].Value, M.Groups["gw"].Value);
                // IPInfo Ip = new IPInfo(M.Groups["ip"].Value,  "0xffffff00", M.Groups["gw"].Value );
                mtxtIPAddress.Text = Ip.IPAddress;
                mtxtSubNet.Text = Ip.SubNet;
                mtxtGateway.Text = Ip.Gateway;
            }
        }