Exemplo n.º 1
0
        public NetworkInfoModel GetNetworkInfo()
        {
            var networkInfoModel = new NetworkInfoModel
            {
                Version         = this.FullNode?.Version?.ToUint() ?? 0,
                SubVersion      = this.Settings?.Agent,
                ProtocolVersion = (uint)(this.Settings?.ProtocolVersion ?? NodeSettings.SupportedProtocolVersion),
                IsLocalRelay    = this.ConnectionManager?.Parameters?.IsRelay ?? false,
                TimeOffset      = this.ConnectionManager?.ConnectedPeers?.GetMedianTimeOffset() ?? 0,
                Connections     = this.ConnectionManager?.ConnectedPeers?.Count(),
                IsNetworkActive = true,
                RelayFee        = this.Settings?.MinRelayTxFeeRate?.FeePerK?.ToUnit(MoneyUnit.BTC) ?? 0,
                IncrementalFee  =
                    this.Settings?.MinRelayTxFeeRate?.FeePerK?.ToUnit(MoneyUnit.BTC) ??
                    0 // set to same as min relay fee
            };

            var services = this.ConnectionManager?.Parameters?.Services;

            if (services != null)
            {
                networkInfoModel.LocalServices = Encoders.Hex.EncodeData(BitConverter.GetBytes((ulong)services));
            }

            return(networkInfoModel);
        }
Exemplo n.º 2
0
        private void FormDevices_Load(object sender, EventArgs e)
        {
            try {
                // create discovery system
                iListenerNotify = new SsdpListenerMulticast();

                // create device lists
                iDeviceListJukebox = new DeviceListUpnp(ServiceJukebox.ServiceType(1), iListenerNotify);

                // hook in to discovery events
                iDeviceListJukebox.EventDeviceAdded   += DeviceAlive;
                iDeviceListJukebox.EventDeviceRemoved += DeviceByeBye;

                NetworkInfoModel iface = iHelper.Interface.Interface.Info;
                if (iface != null)
                {
                    // start discovery process
                    iListenerNotify.Start(iface.IPAddress);
                    iDeviceListJukebox.Start(iface.IPAddress);

                    // improve discovery process
                    iDeviceListJukebox.Rescan();
                }
                else
                {
                    DiscoveryFailed("Device discovery failed: no valid network interface card selected");
                }
            }
            catch (Linn.Network.NetworkError ne) {
                DiscoveryFailed("NetworkError on device discovery: " + ne.Message);
            }
            catch (Exception exc) {
                DiscoveryFailed("Error on device discovery: " + exc.Message);
            }
        }
Exemplo n.º 3
0
        public static List <NetworkInfoModel> GetAllNetworkInterfaces()
        {
            // NetworkInfoModel is a class that we define.  You'll needto define something similar.

            var adaptors = new List <NetworkInfoModel>();

            try
            {
                var networkInterfaceClass        = JNIEnv.FindClass("java/net/NetworkInterface");
                var inetAddressClass             = JNIEnv.FindClass("java/net/InetAddress");
                var getNetworkInterfacesMethod   = JNIEnv.GetStaticMethodID(networkInterfaceClass, "getNetworkInterfaces", "()Ljava/util/Enumeration;");
                var networkInterfacesEnumeration = JNIEnv.CallStaticObjectMethod(networkInterfaceClass, getNetworkInterfacesMethod);
                var enumerationClass             = JNIEnv.FindClass("java/util/Enumeration");
                var hasMoreElementsMethod        = JNIEnv.GetMethodID(enumerationClass, "hasMoreElements", "()Z");
                var nextElementMethod            = JNIEnv.GetMethodID(enumerationClass, "nextElement", "()Ljava/lang/Object;");


                var hasMoreInterfaces = JNIEnv.CallBooleanMethod(networkInterfacesEnumeration, hasMoreElementsMethod);

                int moreInterfacesCount = 0;

                while (hasMoreInterfaces)
                {
                    moreInterfacesCount++;
                    if (moreInterfacesCount > 100)//hack for infinit loop
                    {
                        break;
                    }

                    var currentInterface = JNIEnv.CallObjectMethod(networkInterfacesEnumeration, nextElementMethod);
                    hasMoreInterfaces = JNIEnv.CallBooleanMethod(networkInterfacesEnumeration, hasMoreElementsMethod);

                    var adapter = new Java.Lang.Object(currentInterface, JniHandleOwnership.DoNotTransfer).JavaCast <NetworkInterface>();
                    var getInetAddressesMethod   = JNIEnv.GetMethodID(networkInterfaceClass, "getInetAddresses", "()Ljava/util/Enumeration;");
                    var inetAddressesEnumeration = JNIEnv.CallObjectMethod(currentInterface, getInetAddressesMethod);
                    var hasMoreInetAddresses     = JNIEnv.CallBooleanMethod(inetAddressesEnumeration, hasMoreElementsMethod);



                    // the following methods require android 2.3
                    var isLoopbackMethod = Android.Runtime.JNIEnv.GetMethodID(networkInterfaceClass, "isLoopback", "()Z");
                    var isLoopback       = Android.Runtime.JNIEnv.CallBooleanMethod(currentInterface, isLoopbackMethod);



                    //IntPtr isUpMethod =Android.Runtime.JNIEnv.GetMethodID(networkInterfaceClass, "isUp","()Z");
                    //bool isUp =Android.Runtime.JNIEnv.CallBooleanMethod(currentInterface, isUpMethod);

                    var networkInfo = new NetworkInfoModel
                    {
                        NetworkInterface = adapter,
                        InitAddresses    = new List <InetAddress>(),
                        IpAddresses      = new List <IPAddress>(),
                        // HostNames =  new List<string>(),
                        IsLoopback = isLoopback
                    };

                    int moreInetCount = 0;
                    while (hasMoreInetAddresses)
                    {
                        moreInetCount++;
                        if (moreInetCount > 100) //hack for infinit loop
                        {
                            break;
                        }

                        var currentInetAddress = JNIEnv.CallObjectMethod(inetAddressesEnumeration, nextElementMethod);
                        hasMoreInetAddresses = JNIEnv.CallBooleanMethod(inetAddressesEnumeration, hasMoreElementsMethod);
                        var address = new Java.Lang.Object(currentInetAddress, JniHandleOwnership.DoNotTransfer).JavaCast <InetAddress>();

                        //var getHostNameMethod = Android.Runtime.JNIEnv.GetMethodID(inetAddressClass, "getHostName", "()Ljava/lang/String;");
                        //IntPtr getHostResultPtr = JNIEnv.CallObjectMethod(currentInetAddress, getHostNameMethod);

                        //var getHostResult = new Java.Lang.Object(getHostResultPtr, JniHandleOwnership.TransferLocalRef).JavaCast<Java.Lang.String>();

                        IPAddress ipAddr;

                        var success = IPAddress.TryParse(address.HostAddress, out ipAddr);
                        if (!success)
                        {
                            continue;
                        }

                        networkInfo.InitAddresses.Add(address);
                        networkInfo.IpAddresses.Add(ipAddr);
                        //networkInfo.HostNames.Add(getHostResult.ToString());
                        adaptors.Add(networkInfo);
                    }
                }
            }
            catch (Exception ex)
            {
            }



            return(adaptors);
        }
        public static List<NetworkInfoModel> GetAllNetworkInterfaces()
        {
            // NetworkInfoModel is a class that we define.  You'll needto define something similar.

            var adaptors = new List<NetworkInfoModel>();

            try
            {

                var networkInterfaceClass = JNIEnv.FindClass("java/net/NetworkInterface");
                var inetAddressClass = JNIEnv.FindClass("java/net/InetAddress");
                var getNetworkInterfacesMethod = JNIEnv.GetStaticMethodID(networkInterfaceClass, "getNetworkInterfaces", "()Ljava/util/Enumeration;");
                var networkInterfacesEnumeration = JNIEnv.CallStaticObjectMethod(networkInterfaceClass, getNetworkInterfacesMethod);
                var enumerationClass = JNIEnv.FindClass("java/util/Enumeration");
                var hasMoreElementsMethod = JNIEnv.GetMethodID(enumerationClass, "hasMoreElements", "()Z");
                var nextElementMethod = JNIEnv.GetMethodID(enumerationClass, "nextElement", "()Ljava/lang/Object;");

                var hasMoreInterfaces = JNIEnv.CallBooleanMethod(networkInterfacesEnumeration, hasMoreElementsMethod);

                int moreInterfacesCount = 0;

                while (hasMoreInterfaces)
                {
                    moreInterfacesCount++;
                    if (moreInterfacesCount > 100)//hack for infinit loop
                        break;

                    var currentInterface = JNIEnv.CallObjectMethod(networkInterfacesEnumeration, nextElementMethod);
                    hasMoreInterfaces = JNIEnv.CallBooleanMethod(networkInterfacesEnumeration, hasMoreElementsMethod);

                    var adapter = new Java.Lang.Object(currentInterface, JniHandleOwnership.DoNotTransfer).JavaCast<NetworkInterface>();
                    var getInetAddressesMethod = JNIEnv.GetMethodID(networkInterfaceClass, "getInetAddresses", "()Ljava/util/Enumeration;");
                    var inetAddressesEnumeration = JNIEnv.CallObjectMethod(currentInterface, getInetAddressesMethod);
                    var hasMoreInetAddresses = JNIEnv.CallBooleanMethod(inetAddressesEnumeration, hasMoreElementsMethod);

                    // the following methods require android 2.3
                    var isLoopbackMethod = Android.Runtime.JNIEnv.GetMethodID(networkInterfaceClass, "isLoopback", "()Z");
                    var isLoopback = Android.Runtime.JNIEnv.CallBooleanMethod(currentInterface, isLoopbackMethod);

                    //IntPtr isUpMethod =Android.Runtime.JNIEnv.GetMethodID(networkInterfaceClass, "isUp","()Z");
                    //bool isUp =Android.Runtime.JNIEnv.CallBooleanMethod(currentInterface, isUpMethod);

                    var networkInfo = new NetworkInfoModel
                        {
                            NetworkInterface = adapter,
                            InitAddresses = new List<InetAddress>(),
                            IpAddresses = new List<IPAddress>(),
                           // HostNames =  new List<string>(),
                            IsLoopback = isLoopback
                        };

                    int moreInetCount = 0;
                    while (hasMoreInetAddresses)
                    {
                        moreInetCount++;
                        if (moreInetCount > 100) //hack for infinit loop
                            break;

                        var currentInetAddress = JNIEnv.CallObjectMethod(inetAddressesEnumeration, nextElementMethod);
                        hasMoreInetAddresses = JNIEnv.CallBooleanMethod(inetAddressesEnumeration, hasMoreElementsMethod);
                        var address = new Java.Lang.Object(currentInetAddress, JniHandleOwnership.DoNotTransfer).JavaCast<InetAddress>();

                        //var getHostNameMethod = Android.Runtime.JNIEnv.GetMethodID(inetAddressClass, "getHostName", "()Ljava/lang/String;");
                        //IntPtr getHostResultPtr = JNIEnv.CallObjectMethod(currentInetAddress, getHostNameMethod);

                        //var getHostResult = new Java.Lang.Object(getHostResultPtr, JniHandleOwnership.TransferLocalRef).JavaCast<Java.Lang.String>();

                        IPAddress ipAddr;

                        var success = IPAddress.TryParse(address.HostAddress, out ipAddr);
                        if (!success)
                            continue;

                        networkInfo.InitAddresses.Add(address);
                        networkInfo.IpAddresses.Add(ipAddr);
                        //networkInfo.HostNames.Add(getHostResult.ToString());
                        adaptors.Add(networkInfo);
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return adaptors;
        }