Functions that have just been written to read multiple NIC IP addresses

Source: Internet
Author: User

Although now more than one machine card is very common (like notebook with wire, wireless, Bluetooth, etc.), but find a ready-to-read all the network card IP address of the function is difficult, helpless to write a, good things who use who know.

[C-sharp]View PlainCopy
  1. Uses WinSock;
  2. Type
  3. Paddrinfow = ^addrinfow;
  4. Addrinfow = Record
  5. Ai_flags:integer; //Ai_passive, Ai_canonname, Ai_numerichost
  6. Ai_family:integer; //Pf_xxx
  7. Ai_socktype:integer; //Sock_xxx
  8. Ai_protocol:integer; //0 or Ipproto_xxx for IPv4 and IPv6
  9. Ai_addrlen:ulong; //Length of AI_ADDR
  10. Ai_canonname:pwidechar; //Canonical name for NodeName
  11. AI_ADDR:PSOCKADDR; //Binary address
  12. Ai_next:paddrinfow; //Next structure in linked list
  13. End
  14. Ppaddrinfow = ^paddrinfow;
  15. Taddrinfow = addrinfow;
  16. function Getaddrinfow (Nodename:pwidechar; Servicename:pwidechar; Hints:paddrinfow; PPRESULT:PPADDRINFOW): Integer; stdcall;  External ' ws2_32.dll ' name ' getaddrinfow ';
  17. Procedure Freeaddrinfow (AI:PADDRINFOW); stdcall; stdcall;  External ' ws2_32.dll ' name ' freeaddrinfow ';
  18. Procedure Getiplist (list:tstrings);
  19. Var
  20. BUFFER:ARRAY[0..63] of Ansichar;
  21. Hostname: string;
  22. Hints:taddrinfow;
  23. Laddrinfo:paddrinfow;
  24. Retval:integer;
  25. Ginitdata:twsadata;
  26. Begin
  27. WSAStartup ($101, ginitdata);
  28. GetHostName (buffer, SizeOf (buffer));
  29. Hostname: = string (Buffer);
  30. ZeroMemory (@Hints, SizeOf (taddrinfow));
  31. Hints.ai_family: = 2{af_inet};
  32. Hints.ai_socktype: = 1{sock_stream};
  33. Laddrinfo: = nil;
  34. RetVal: = Getaddrinfow (PChar (Hostname), nil, @Hints, @LAddrInfo);
  35. Try
  36. if (RetVal = 0) and (laddrinfo <> nil) Then
  37. Repeat
  38. With Tinaddr (LADDRINFO^.AI_ADDR^.SIN_ADDR). S_un_b Do
  39. List.add (Format ('%d.%d.%d.%d ', [Byte (S_B1), Byte (s_b2), Byte (s_b3), Byte (S_B4)]));
  40. Laddrinfo: = Laddrinfo^.ai_next;
  41. Until Laddrinfo = nil;
  42. finally
  43. Freeaddrinfow (Laddrinfo);
  44. WSACleanup;
  45. End
  46. End

PS: I use the D2009, with the low version D friend trouble oneself changed.

http://blog.csdn.net/nhconch/article/details/4897682

Functions that have just been written to read multiple NIC IP addresses

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.