private Task RunGetDhcpInfoAsync(HostInfo hostInfo) { var task = Task <DhcpInfo> .Factory.StartNew(() => { var dhcpInfoService = ServiceProvider.GetService <IDhcpInfoService>(); var result = dhcpInfoService.GetDhcpInfo(hostInfo.NetworkAdapterId); if (result == null) { throw new Exception("GetDhcpInfo failed"); } return(result); }); DhcpInfoTaskStatus = TaskStatus.Running; var completedTask = WrapTask( task, TaskScheduler.FromCurrentSynchronizationContext(), Strings.Status_GetDhcpInfoFailed, t => { #if SCREENSHOT DhcpInfo = new DhcpInfo(t.Result.GatewayAddress, t.Result.DnsServerAddress, "my-domain-name"); #else DhcpInfo = t.Result; #endif DhcpInfoTaskStatus = TaskStatus.RanToCompletion; }, t => { DhcpInfoTaskStatus = TaskStatus.Faulted; }); return(completedTask); }
public MockServiceProvider(MockServiceProviderOptions options) { if (options == null) { throw new ArgumentNullException("options"); } m_settingsPropertyStore = options.SettingsPropertyStore; m_hostInfo = options.HostInfo; m_connectionInfo = options.ConnectionInfo; m_dhcpInfo = options.DhcpInfo; m_externalAddress = options.ExternalAddress; }
public void DHCPInfo() { WifiManager wifiManager = (WifiManager)(Application.Context.GetSystemService(Context.WifiService)); DhcpInfo dhcpinfo = wifiManager.DhcpInfo; ip2 = Android.Text.Format.Formatter.FormatIpAddress(dhcpinfo.IpAddress); mask = Android.Text.Format.Formatter.FormatIpAddress(dhcpinfo.Netmask); gateway = Android.Text.Format.Formatter.FormatIpAddress(dhcpinfo.Gateway); dns1 = Android.Text.Format.Formatter.FormatIpAddress(dhcpinfo.Dns1); dns2 = Android.Text.Format.Formatter.FormatIpAddress(dhcpinfo.Dns2); dhcp = Android.Text.Format.Formatter.FormatIpAddress(dhcpinfo.ServerAddress); leaseduration = dhcpinfo.LeaseDuration; }
public string GetBroadcastAddress() { Log.Debug("UDP", "Getting broadcast adress"); WifiManager wifi = (WifiManager)Android.App.Application.Context.GetSystemService(Context.WifiService); DhcpInfo dhcp = wifi.DhcpInfo; // handle null somehow int broadcast = (dhcp.IpAddress & dhcp.Netmask) | ~dhcp.Netmask; byte[] quads = new byte[4]; for (int k = 0; k < 4; k++) { quads[k] = (byte)((broadcast >> k * 8) & 0xFF); } Log.Debug("UDP", "Adrress is: " + InetAddress.GetByAddress(quads)); return(InetAddress.GetByAddress(quads).ToString()); }
//ブロードキャストアドレスの取得 InetAddress getBroadcastAddress() { DhcpInfo dhcpInfo = wifi.DhcpInfo; int broadcast = (dhcpInfo.IpAddress & dhcpInfo.Netmask) | ~dhcpInfo.Netmask; byte[] quads = new byte[4]; for (int i = 0; i < 4; i++) { quads[i] = (byte)((broadcast >> i * 8) & 0xFF); } try { return(InetAddress.GetByAddress(quads)); } catch (IOException e) { e.PrintStackTrace(); return(null); } }
public DhcpInfo GetDhcpInfo(Guid networkAdapterId) { var result = DhcpInfo.GetDhcpInfo(networkAdapterId); return(result); }
protected override void BecauseOf() { m_result = new DhcpInfo(GatewayAddress, DnsServerAddress, DomainName); }
WifiConnectionInfo TryConnectViaMethod(WifiNetworkDto dto) { string bssid = dto.BssID; string ssid = dto.Name; string password = dto.Password; var formattedSsid = $"\"{ssid}\""; var formattedPassword = $"\"{password}\""; WifiConnectionInfo info2 = null; var wifiConfig = new WifiConfiguration { Bssid = bssid, Ssid = formattedSsid, Priority = Constants.WIFI_CONFIG_PRIORITY }; if (dto.NetworkType.Contains("[WEP]")) { // for WEP wifiConfig.WepKeys[0] = formattedPassword; wifiConfig.WepTxKeyIndex = 0; wifiConfig.AllowedKeyManagement.Set((int)KeyManagementType.None); wifiConfig.AllowedProtocols.Set((int)Android.Net.Wifi.ProtocolType.Rsn); wifiConfig.AllowedGroupCiphers.Set((int)Android.Net.Wifi.GroupCipherType.Wep40); wifiConfig.AllowedProtocols.Set((int)Android.Net.Wifi.ProtocolType.Wpa); wifiConfig.AllowedGroupCiphers.Set((int)Android.Net.Wifi.GroupCipherType.Wep104); } else if (dto.NetworkType.Contains("[WPA")) { //wifiConfig.AllowKeyManagement.Set((int)KeyManagementType.WpaPsk); wifiConfig.PreSharedKey = formattedPassword; } else { // open networks wifiConfig.AllowedProtocols.Set((int)Android.Net.Wifi.ProtocolType.Rsn); wifiConfig.AllowedKeyManagement.Set((int)KeyManagementType.None); } var wifiManager = (WifiManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.WifiService); var connManager = (ConnectivityManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.ConnectivityService); var ni1 = connManager.ActiveNetworkInfo; if (ni1 != null && ni1.IsConnected && ni1.Type == ConnectivityType.Wifi) { //WifiConnectionInfo info = new WifiConnectionInfo //{ // FirstConnectMac = wifiManager.ConnectionInfo.MacAddress, //}; return(null); } else { wifiManager.SetWifiEnabled(true); var addNetworkIdx = wifiManager.AddNetwork(wifiConfig); var bd = wifiManager.Disconnect(); var enableNetwork = wifiManager.EnableNetwork(addNetworkIdx, true); var brc = wifiManager.Reconnect(); DhcpInfo dhcpInfo = wifiManager.DhcpInfo; //byte[] ipAddress = BitConverter.GetBytes(dhcpInfo.Gateway); int gwip = wifiManager.DhcpInfo.Gateway; Task.Delay(500); gwip = wifiManager.DhcpInfo.Gateway; var gwAddr = (gwip & 0xFF) + "." + ((gwip >> 8) & 0xFF) + "." + ((gwip >> 16) & 0xFF) + "." + ((gwip >> 24) & 0xFF); info2 = new WifiConnectionInfo { FirstConnectMac = wifiManager.ConnectionInfo.MacAddress, // https://theconfuzedsourcecode.wordpress.com/2015/05/16/how-to-easily-get-device-ip-address-in-xamarin-forms-using-dependencyservice/ RouterWebUIIP = gwAddr //DependencyService.Get<IIPAddressManager>().GetIPAddress(), }; } var isConnectedToAP = wifiManager.ConnectionInfo.BSSID != "00:00:00:00:00:00" && info2.RouterWebUIIP != "127.0.0.1" && info2.RouterWebUIIP != "0.0.0.0"; return(isConnectedToAP ? info2 : null); }
protected override void BecauseOf() { m_result = new DhcpInfo(GatewayAddress, DnsServerAddress, DomainName); }