public static IList <IP_ADAPTER_ADDRESSES> GetIPAdapters(FAMILY family) { List <IP_ADAPTER_ADDRESSES> adapters = new List <IP_ADAPTER_ADDRESSES>(); uint outBufLen = 1500; uint MAX_TRIES = 3; uint iterations = 0; uint Flags = (uint)FLAGS.GAA_FLAG_INCLUDE_PREFIX; ERROR err; do { IntPtr pAdapterAddresses = Marshal.AllocHGlobal((int)outBufLen); err = GetAdaptersAddresses((uint)FAMILY.AF_INET, Flags, IntPtr.Zero, pAdapterAddresses, ref outBufLen); if (err == ERROR.ERROR_BUFFER_OVERFLOW) { Marshal.FreeHGlobal(pAdapterAddresses); } else { IntPtr currPtr = pAdapterAddresses; while (IntPtr.Zero != currPtr) { IP_ADAPTER_ADDRESSES addr = (IP_ADAPTER_ADDRESSES)Marshal.PtrToStructure(currPtr, typeof(IP_ADAPTER_ADDRESSES)); adapters.Add(addr); currPtr = addr.Next; } } iterations++; }while ((err == ERROR.ERROR_BUFFER_OVERFLOW) && (iterations < MAX_TRIES)); return(adapters); }
public static IList <IP_ADAPTER_ADDRESSES> GetIPAdapters(FAMILY family) { List <IP_ADAPTER_ADDRESSES> adapters = new List <IP_ADAPTER_ADDRESSES>(); uint outBufLen = 0; ERROR err = GetAdaptersAddresses((uint)family, (uint)0, IntPtr.Zero, IntPtr.Zero, ref outBufLen); if (ERROR.ERROR_BUFFER_OVERFLOW == err) { IntPtr pAdapterAddresses = Marshal.AllocHGlobal((int)outBufLen); try { err = GetAdaptersAddresses((uint)FAMILY.AF_INET, (uint)0, IntPtr.Zero, pAdapterAddresses, ref outBufLen); if (ERROR.ERROR_SUCCESS == err) { IntPtr currPtr = pAdapterAddresses; while (IntPtr.Zero != currPtr) { IP_ADAPTER_ADDRESSES addr = (IP_ADAPTER_ADDRESSES)Marshal.PtrToStructure(currPtr, typeof(IP_ADAPTER_ADDRESSES)); adapters.Add(addr); currPtr = addr.Next; } } } finally { Marshal.FreeHGlobal(pAdapterAddresses); } } return(adapters); }
public FamilySearchView(FAMILY family) { this.FAMILYID = family.FAMILYID; this.LASTNAME = family.LASTNAME; this.ADDRESS = family.ADDRESS; this.ZIPCODE = family.ZIPCODE; this.CITY = family.CITY; this.EMAIL = family.EMAIL; }
internal static List<AdapterInfo> GetAdaptersAddresses(FAMILY family, GetAdapterFlags flags) { IP_ADAPTER_ADDRESSES structure; int num = 0; List<AdapterInfo> adapterInfos = new List<AdapterInfo>(); AdapterInfo strs = new AdapterInfo(); win32._GetAdaptersAddresses((uint)family, (uint)flags, IntPtr.Zero, IntPtr.Zero, ref num); IntPtr intPtr = Marshal.AllocHGlobal(num); win32._GetAdaptersAddresses((uint)family, (uint)flags, IntPtr.Zero, intPtr, ref num); for (IntPtr i = intPtr; IntPtr.Zero != i; i = structure.Next) { strs.Ipv4 = new List<string>(); strs.Ipv6 = new List<string>(); structure = (IP_ADAPTER_ADDRESSES)Marshal.PtrToStructure(i, typeof(IP_ADAPTER_ADDRESSES)); IntPtr firstUnicastAddress = structure.FirstUnicastAddress; strs.Description = structure.Description; strs.FriendlyName = structure.FriendlyName; strs.DNSSuffix = structure.DnsSuffix; strs.IfType = (InterfaceType)structure.IfType; uint num1 = 0; uint num2 = 0; while (IntPtr.Zero != firstUnicastAddress) { IP_ADAPTER_UNICAST_ADDRESS pADAPTERUNICASTADDREss = (IP_ADAPTER_UNICAST_ADDRESS)Marshal.PtrToStructure(firstUnicastAddress, typeof(IP_ADAPTER_UNICAST_ADDRESS)); int address = pADAPTERUNICASTADDREss.Address.iSockaddrLength; if (address == 16) { IP_V4_ADDRESS pV4ADDREss = (IP_V4_ADDRESS)Marshal.PtrToStructure(pADAPTERUNICASTADDREss.Address.lpSockAddr, typeof(IP_V4_ADDRESS)); object[] sinAddr = new object[7]; sinAddr[0] = pV4ADDREss.sin_addr[0]; sinAddr[1] = "."; sinAddr[2] = pV4ADDREss.sin_addr[1]; sinAddr[3] = "."; sinAddr[4] = pV4ADDREss.sin_addr[2]; sinAddr[5] = "."; sinAddr[6] = pV4ADDREss.sin_addr[3]; string str = string.Concat(sinAddr); strs.Ipv4.Add(str); num1++; } else { if (address == 28) { IP_V6_ADDRESS pV6ADDREss = (IP_V6_ADDRESS)Marshal.PtrToStructure(pADAPTERUNICASTADDREss.Address.lpSockAddr, typeof(IP_V6_ADDRESS)); strs.Ipv6.Add(utility.FormatAsIPv6Address(pV6ADDREss.sin6_addr)); num2++; } } firstUnicastAddress = pADAPTERUNICASTADDREss.Next; } adapterInfos.Add(strs); } Marshal.FreeHGlobal(intPtr); return adapterInfos; }
private static FAMILY CreateFamily(ExcelModel _ExcelModel, EGOEntities _EGOEntities) { FAMILY Family = new FAMILY(); Family.LASTNAME = _ExcelModel.NOM.ToUpper(); Family.ADDRESS = _ExcelModel.ADRESSE; Family.ZIPCODE = _ExcelModel.CP; Family.CITY = _ExcelModel.VILLE; Family.EMAIL = _ExcelModel.EMAIL; _EGOEntities.FAMILY.Add(Family); return(Family); }
public static IList <IPAddress> GetIPAddresses(FAMILY family) { List <IPAddress> addresses = new List <IPAddress>(); foreach (IP_ADAPTER_ADDRESSES addr in GetIPAdapters(family)) { if (IntPtr.Zero != addr.FirstUnicastAddress) { IP_ADAPTER_UNICAST_ADDRESS unicastAddr = (IP_ADAPTER_UNICAST_ADDRESS)Marshal.PtrToStructure(addr.FirstUnicastAddress, typeof(IP_ADAPTER_UNICAST_ADDRESS)); if (IntPtr.Zero != unicastAddr.Address.lpSockAddr) { SOCKADDR socketAddr = (SOCKADDR)Marshal.PtrToStructure(unicastAddr.Address.lpSockAddr, typeof(SOCKADDR)); byte[] saData = socketAddr.sa_data.Skip(2).Take(4).ToArray(); IPAddress ipAddr = new IPAddress(saData); addresses.Add(ipAddr); } } } return(addresses); }
protected object GetObjectById(int _id, bool _master, string _slaveType, string _masterType) { switch (typeof(T).Name) { case "FAMILY": FAMILY family = null; if (_id == 0) { family = egoEntities.FAMILY.FirstOrDefault(); } else { family = egoEntities.FAMILY.FirstOrDefault(x => x.FAMILYID == _id); } return(family == null ? new FAMILY() : family); case "PERSON": PERSON person = null; if (_master) { person = _id == 0 ? egoEntities.PERSON.FirstOrDefault() : egoEntities.PERSON.FirstOrDefault(x => x.PERSONID == _id); } else { if (_masterType == "GYMGROUP") { PERSON_GYMGROUP person_gymGroup = new PERSON_GYMGROUP(); person_gymGroup = _id == 0 ? egoEntities.PERSON_GYMGROUP.FirstOrDefault() : egoEntities.PERSON_GYMGROUP.FirstOrDefault(x => x.PERSON_GYMGROUP_ID == _id); return(person_gymGroup == null ? new PERSON_GYMGROUP() : person_gymGroup); } else if (_masterType == "FAMILY") { person = _id == 0 ? egoEntities.PERSON.FirstOrDefault() : egoEntities.PERSON.FirstOrDefault(x => x.PERSONID == _id); } } return(person == null ? new PERSON() : person); case "PHONE": PHONE Phone = null; Phone = _id == 0 ? egoEntities.PHONE.FirstOrDefault() : egoEntities.PHONE.FirstOrDefault(x => x.PHONEID == _id); return(Phone == null ? new PHONE() : Phone); case "DISCOUNT": DISCOUNT Discount = null; Discount = _id == 0 ? egoEntities.DISCOUNT.FirstOrDefault() : egoEntities.DISCOUNT.FirstOrDefault(x => x.DISCOUNTID == _id); return(Discount == null ? new DISCOUNT() : Discount); case "PAYMENT": PAYMENT Payment = null; Payment = _id == 0 ? egoEntities.PAYMENT.FirstOrDefault() : egoEntities.PAYMENT.FirstOrDefault(x => x.PAYMENTID == _id); return(Payment == null ? new PAYMENT() : Payment); case "DOCUMENT": DOCUMENT Document = null; Document = _id == 0 ? egoEntities.DOCUMENT.FirstOrDefault() : egoEntities.DOCUMENT.FirstOrDefault(x => x.DOCUMENTID == _id); return(Document == null ? new DOCUMENT() : Document); case "GYMGROUP": if (_master) { GYMGROUP GymGroup = null; GymGroup = _id == 0 ? egoEntities.GYMGROUP.FirstOrDefault() : egoEntities.GYMGROUP.FirstOrDefault(x => x.GYMGROUPID == _id); return(GymGroup == null ? new GYMGROUP() : GymGroup); } else { PERSON_GYMGROUP Person_GymGroup = new PERSON_GYMGROUP(); Person_GymGroup = _id == 0 ? egoEntities.PERSON_GYMGROUP.FirstOrDefault() : egoEntities.PERSON_GYMGROUP.First(x => x.PERSON_GYMGROUP_ID == _id); return(Person_GymGroup == null ? new PERSON_GYMGROUP() : Person_GymGroup); } } return(null); }
public static IList<IPAddress> GetIPAddresses(FAMILY family) { List<IPAddress> addresses = new List<IPAddress>(); foreach (IP_ADAPTER_ADDRESSES addr in GetIPAdapters(family)) { if (IntPtr.Zero != addr.FirstUnicastAddress) { IP_ADAPTER_UNICAST_ADDRESS unicastAddr = (IP_ADAPTER_UNICAST_ADDRESS)Marshal.PtrToStructure(addr.FirstUnicastAddress, typeof(IP_ADAPTER_UNICAST_ADDRESS)); if (IntPtr.Zero != unicastAddr.Address.lpSockAddr) { SOCKADDR socketAddr = (SOCKADDR)Marshal.PtrToStructure(unicastAddr.Address.lpSockAddr, typeof(SOCKADDR)); byte[] saData = socketAddr.sa_data.Skip(2).Take(4).ToArray(); IPAddress ipAddr = new IPAddress(saData); addresses.Add(ipAddr); } } } return addresses; }
public static IList<IP_ADAPTER_ADDRESSES> GetIPAdapters(FAMILY family) { List<IP_ADAPTER_ADDRESSES> adapters = new List<IP_ADAPTER_ADDRESSES>(); uint outBufLen = 1500; uint MAX_TRIES = 3; uint iterations = 0; uint Flags = (uint)FLAGS.GAA_FLAG_INCLUDE_PREFIX; ERROR err; do { IntPtr pAdapterAddresses = Marshal.AllocHGlobal((int)outBufLen); err = GetAdaptersAddresses((uint)FAMILY.AF_INET, Flags, IntPtr.Zero, pAdapterAddresses, ref outBufLen); if (err == ERROR.ERROR_BUFFER_OVERFLOW) { Marshal.FreeHGlobal(pAdapterAddresses); } else { IntPtr currPtr = pAdapterAddresses; while (IntPtr.Zero != currPtr) { IP_ADAPTER_ADDRESSES addr = (IP_ADAPTER_ADDRESSES)Marshal.PtrToStructure(currPtr, typeof(IP_ADAPTER_ADDRESSES)); adapters.Add(addr); currPtr = addr.Next; } } iterations++; } while ((err == ERROR.ERROR_BUFFER_OVERFLOW) && (iterations < MAX_TRIES)); return adapters; }
// Route functions // =============== /// <summary> /// XP - IPv4 Only /// </summary> /// <param name="family"></param> /// <returns></returns> public static List<Route> GetRoutes(FAMILY family) { List<Route> routes = new List<Route>(); if (Environment.OSVersion.Version.CompareTo(new Version("6.0")) < 0) { if (family == FAMILY.AF_INET6) return routes; uint dwSize = 0; IntPtr pNull = IntPtr.Zero; GetIpForwardTable(pNull, ref dwSize, true); IntPtr pIpForwardTable = Marshal.AllocHGlobal((int)dwSize); GetIpForwardTable(pIpForwardTable, ref dwSize, true); MIB_IPFORWARDTABLE table = (MIB_IPFORWARDTABLE)Marshal.PtrToStructure(pIpForwardTable, typeof(MIB_IPFORWARDTABLE)); IntPtr pRow = pIpForwardTable + Marshal.SizeOf(table.dwNumEntries); for (int i = 0; i < table.dwNumEntries; i++) { MIB_IPFORWARDROW row = (MIB_IPFORWARDROW)Marshal.PtrToStructure(pRow, typeof(MIB_IPFORWARDROW)); Route route = new Route(); route.Destination = new IPAddress(row.dwForwardDest).ToString(); route.Prefix = new IPAddress(row.dwForwardMask).ToString(); route.Gateway = new IPAddress(row.dwForwardNextHop).ToString(); route.InterfaceIndex = (int)row.dwForwardIfIndex; route.Age = row.dwForwardAge; route.Metric = (ushort)row.dwForwardMetric1; route.Type = row.dwForwardType; route.Protocol = row.dwForwardProto; route.IPVersion = 4; routes.Add(route); pRow += Marshal.SizeOf(typeof(MIB_IPFORWARDROW)); } Marshal.FreeHGlobal(pIpForwardTable); } else { IntPtr pTable; GetIpForwardTable2(family, out pTable); MIB_IPFORWARD_TABLE2 table = (MIB_IPFORWARD_TABLE2)Marshal.PtrToStructure(pTable, typeof(MIB_IPFORWARD_TABLE2)); IntPtr pRow = pTable + Marshal.SizeOf(table.NumEntries) + 4; for (int i = 0; i < table.NumEntries; i++) { MIB_IPFORWARD_ROW2 row = (MIB_IPFORWARD_ROW2)Marshal.PtrToStructure(pRow, typeof(MIB_IPFORWARD_ROW2)); Route route = new Route(); route.Prefix = row.DestinationPrefix.PrefixLength.ToString(); route.InterfaceIndex = (int)row.InterfaceIndex; route.Age = row.Age; route.Metric = (ushort)row.Metric; if (row.DestinationPrefix.Prefix.Ipv4.sin_family == FAMILY.AF_INET) { route.Destination = new IPAddress(row.DestinationPrefix.Prefix.Ipv4.sin_addr.S_addr).ToString(); route.Gateway = new IPAddress(row.NextHop.Ipv4.sin_addr.S_addr).ToString(); IP.ValidateIPv4Mask(ref route.Prefix); route.IPVersion = 4; } else { route.Destination = new IPAddress(row.DestinationPrefix.Prefix.Ipv6.sin6_addr.Byte).ToString(); route.Gateway = new IPAddress(row.NextHop.Ipv6.sin6_addr.Byte).ToString(); route.IPVersion = 6; } routes.Add(route); pRow += Marshal.SizeOf(typeof(MIB_IPFORWARD_ROW2)); } FreeMibTable(pTable); } return routes; }
public static extern ERROR GetExtendedUdpTable(IntPtr pUdpTable, ref int dwSize, bool bOrder, FAMILY Family, UDP_TABLE_CLASS TableClass, uint Reserved);
// Adapters functions // ================== public static List<Adapter> GetAdapters(FAMILY family) { List<Adapter> adapters = new List<Adapter>(); if (Environment.OSVersion.Version.CompareTo(new Version("6.0")) < 0) { uint outBufLen = 0; ERROR error = GetAdaptersInfo(IntPtr.Zero, ref outBufLen); if (error == ERROR.ERROR_BUFFER_OVERFLOW) { IntPtr pAdapterInfo = Marshal.AllocHGlobal((int)outBufLen); error = GetAdaptersInfo(pAdapterInfo, ref outBufLen); if (error == ERROR.ERROR_SUCCESS) { IntPtr pCurrAdapterInfo = pAdapterInfo; while(pCurrAdapterInfo != IntPtr.Zero) { IP_ADAPTER_INFO adapterInfo = (IP_ADAPTER_INFO)Marshal.PtrToStructure(pCurrAdapterInfo, typeof(IP_ADAPTER_INFO)); Adapter adapter = new Adapter(); adapter.Guid = adapterInfo.AdapterName; adapter.UnicastAddresses.Add(new Adapter.UnicastAddress(adapterInfo.IpAddressList.IpAddress, adapterInfo.IpAddressList.IpMask)); IntPtr pUnicastAddress = adapterInfo.IpAddressList.Next; while (pUnicastAddress != IntPtr.Zero) { IP_ADDR_STRING unicastAddress = (IP_ADDR_STRING)Marshal.PtrToStructure(pUnicastAddress, typeof(IP_ADDR_STRING)); adapter.UnicastAddresses.Add(new Adapter.UnicastAddress(unicastAddress.IpAddress, unicastAddress.IpMask)); pUnicastAddress = unicastAddress.Next; } adapter.GatewayAddresses.Add(adapterInfo.GatewayList.IpAddress); IntPtr pGatewayAdress = adapterInfo.GatewayList.Next; while (pGatewayAdress != IntPtr.Zero) { IP_ADDR_STRING gatewayAddress = (IP_ADDR_STRING)Marshal.PtrToStructure(pGatewayAdress, typeof(IP_ADDR_STRING)); adapter.GatewayAddresses.Add(gatewayAddress.IpAddress); pGatewayAdress = gatewayAddress.Next; } adapter.DhcpEnabled = adapterInfo.DhcpEnabled > 0; adapter.Dhcpv4Server = adapterInfo.DhcpServer.IpAddress; adapter.InterfaceIndex = adapterInfo.Index; adapters.Add(adapter); pCurrAdapterInfo = adapterInfo.Next; } } Marshal.FreeHGlobal(pAdapterInfo); } } else { uint outBufLen = 0; ERROR error = GetAdaptersAddresses((uint)family, 0, IntPtr.Zero, IntPtr.Zero, ref outBufLen); if (error == ERROR.ERROR_BUFFER_OVERFLOW) { IntPtr pAdapterAddresses = Marshal.AllocHGlobal((int)outBufLen); error = GetAdaptersAddresses((uint)family, 0, IntPtr.Zero, pAdapterAddresses, ref outBufLen); if (error == ERROR.ERROR_SUCCESS) { IntPtr currPtr = pAdapterAddresses; while (currPtr != IntPtr.Zero) { IP_ADAPTER_ADDRESSES adapterAddress = (IP_ADAPTER_ADDRESSES)Marshal.PtrToStructure(currPtr, typeof(IP_ADAPTER_ADDRESSES)); Adapter adapter = new Adapter(); adapter.Guid = Marshal.PtrToStringAnsi(adapterAddress.AdapterName); IntPtr pUnicastAddress = adapterAddress.FirstUnicastAddress; while (pUnicastAddress != IntPtr.Zero) { IP_ADAPTER_UNICAST_ADDRESS unicastAddress = (IP_ADAPTER_UNICAST_ADDRESS)Marshal.PtrToStructure(pUnicastAddress, typeof(IP_ADAPTER_UNICAST_ADDRESS)); SOCKADDR address = (SOCKADDR)Marshal.PtrToStructure(unicastAddress.Address.lpSockAddr, typeof(SOCKADDR)); if (address.sa_family == FAMILY.AF_INET) { SOCKADDR_IN ipv4Address = (SOCKADDR_IN)Marshal.PtrToStructure(unicastAddress.Address.lpSockAddr, typeof(SOCKADDR_IN)); adapter.UnicastAddresses.Add(new Adapter.UnicastAddress(new IPAddress(ipv4Address.sin_addr.S_addr).ToString(), unicastAddress.OnLinkPrefixLength)); } else if (address.sa_family == FAMILY.AF_INET6) { SOCKADDR_IN6 ipv6Address = (SOCKADDR_IN6)Marshal.PtrToStructure(unicastAddress.Address.lpSockAddr, typeof(SOCKADDR_IN6)); adapter.UnicastAddresses.Add(new Adapter.UnicastAddress(new IPAddress(ipv6Address.sin6_addr.Byte).ToString(), unicastAddress.OnLinkPrefixLength)); } pUnicastAddress = unicastAddress.Next; } IntPtr pGatewayAddress = adapterAddress.FirstGatewayAddress; while (pGatewayAddress != IntPtr.Zero) { IP_ADAPTER_GATEWAY_ADDRESS gatewayAddress = (IP_ADAPTER_GATEWAY_ADDRESS)Marshal.PtrToStructure(pGatewayAddress, typeof(IP_ADAPTER_GATEWAY_ADDRESS)); SOCKADDR address = (SOCKADDR)Marshal.PtrToStructure(gatewayAddress.Address.lpSockAddr, typeof(SOCKADDR)); if (address.sa_family == FAMILY.AF_INET) { SOCKADDR_IN ipv4Address = (SOCKADDR_IN)Marshal.PtrToStructure(gatewayAddress.Address.lpSockAddr, typeof(SOCKADDR_IN)); adapter.GatewayAddresses.Add(new IPAddress(ipv4Address.sin_addr.S_addr).ToString()); } else if (address.sa_family == FAMILY.AF_INET6) { SOCKADDR_IN6 ipv6Address = (SOCKADDR_IN6)Marshal.PtrToStructure(gatewayAddress.Address.lpSockAddr, typeof(SOCKADDR_IN6)); adapter.GatewayAddresses.Add(new IPAddress(ipv6Address.sin6_addr.Byte).ToString()); } pGatewayAddress = gatewayAddress.Next; } adapter.DhcpEnabled = (adapterAddress.Flags & IP_ADAPTER_DHCP_ENABLED) > 0; if (adapterAddress.Dhcpv4Server.lpSockAddr != IntPtr.Zero) { SOCKADDR_IN dhcpv4Server = (SOCKADDR_IN)Marshal.PtrToStructure(adapterAddress.Dhcpv4Server.lpSockAddr, typeof(SOCKADDR_IN)); adapter.Dhcpv4Server = new IPAddress(dhcpv4Server.sin_addr.S_addr).ToString(); } if (adapterAddress.Dhcpv6Server.lpSockAddr != IntPtr.Zero) { SOCKADDR_IN6 dhcpv6Server = (SOCKADDR_IN6)Marshal.PtrToStructure(adapterAddress.Dhcpv6Server.lpSockAddr, typeof(SOCKADDR_IN6)); adapter.Dhcpv6Server = new IPAddress(dhcpv6Server.sin6_addr.Byte).ToString(); } adapter.InterfaceIndex = adapterAddress.Alignment.IfIndex; adapter.IPv4InterfaceMetric = adapterAddress.Ipv4Metric; adapter.IPv6InterfaceMetric = adapterAddress.Ipv6Metric; adapters.Add(adapter); currPtr = adapterAddress.Next; } } Marshal.FreeHGlobal(pAdapterAddresses); } } return adapters; }
public static extern uint GetIpForwardTable2(FAMILY Family, out IntPtr Table);