UdpSocket1 - & gt; LocalHostName ();
UdpSocket1 - & gt; LocalHostAddr ();
CodePudding user response:
The components have no this function, you can use the system (" ipconfig & gt;> Tt. TXT ") from tt. TXT find mask, and gatewayCodePudding user response:
Subnet mask and gateway, can use the function of iphlpapi,CodePudding user response:
The inside of the MSDN code:PIP_ADAPTER_INFO pAdapterInfo;
PIP_ADAPTER_INFO pAdapter=NULL;
DWORD dwRetVal=0;
PAdapterInfo=(IP_ADAPTER_INFO *) malloc (sizeof (IP_ADAPTER_INFO));
ULONG ulOutBufLen=sizeof (IP_ADAPTER_INFO);
//Make an initial call to GetAdaptersInfo to get
//the necessary size into the ulOutBufLen variable
If (GetAdaptersInfo (pAdapterInfo, & amp; UlOutBufLen)=={ERROR_BUFFER_OVERFLOW)
Free (pAdapterInfo);
PAdapterInfo=(IP_ADAPTER_INFO *) malloc (ulOutBufLen);
}
If ((dwRetVal=GetAdaptersInfo (pAdapterInfo, & amp; UlOutBufLen))=={NO_ERROR)
PAdapter=pAdapterInfo;
While (pAdapter) {
Printf (" \ tAdapter Name: \ n \ t % s ", pAdapter - & gt; AdapterName);
Printf (" \ tAdapter Desc: \ n \ t % s ", pAdapter - & gt; The Description);
Printf (" \ tAdapter Addr: \ t % ld \ n ", pAdapter - & gt; Address);
Printf (" \ tIP Address: \ n \ t % s ", pAdapter - & gt; IpAddressList. IpAddress. String);
Printf (" \ tIP Mask: \ n \ t % s ", pAdapter - & gt; IpAddressList. IpMask. String);
Printf (" % s \ n \ tGateway: \ t ", pAdapter - & gt; GatewayList. IpAddress. String);
Printf (" \ t \ n * * * ");
If (pAdapter - & gt; DhcpEnabled) {
Printf (" \ tDHCP Enabled: Yes \ n ");
Printf (" \ \ t tDHCP Server: \ n \ t % s ", pAdapter - & gt; DhcpServer. IpAddress. String);
Printf (" \ tLease Obtained: % ld \ n ", pAdapter - & gt; LeaseObtained);
}
The else
Printf (" \ tDHCP Enabled: No \ n ");
If (pAdapter - & gt; HaveWins) {
Printf (" \ tHave Wins: Yes \ n ");
Printf (" \ \ t tPrimary Wins Server: \ n \ t % s ", pAdapter - & gt; PrimaryWinsServer. IpAddress. String);
Printf (" \ \ t tSecondary Wins Server: \ n \ t % s ", pAdapter - & gt; SecondaryWinsServer. IpAddress. String);
}
The else
Printf (" \ tHave Wins: No \ n ");
PAdapter=pAdapter - & gt; Next;
}
}
The else {
Printf (" Call to GetAdaptersInfo failed. \ n ");
}
CodePudding user response:
//* * * * * * * get this pattern of function * * * * * * * * *String GetHostName (void) {
//returns the native network name
WSAData WSAData;
String OutStr="";
String PCName="";
String HostNameGet;
Char AHost [50].
WSAStartup (MAKEWORD (2, 0), & amp; WsaData);
Gethostname (AHost, 50);
HostNameGet=AHost;
Struct hostent * HP=gethostbyname (HostNameGet c_str ());
PCName=HP - & gt; H_name;
OutStr=PCName;
WSACleanup ();
Return OutStr;
};
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//* * * * * * * to get the machine IP function * * * * * * * * *
String GetHostIPAddress (String HostNameIn, int ListNO)
{//in accordance with the network name to get IP address, parameters for the network name, 1 parameters for IP cases 2 different IP
WSAData WSAData;
String PCName="";
String IPAddress;
String OutStr="";
Struct hostent * HP;
Char AHost [50].
WSAStartup (MAKEWORD (2, 0), & amp; WsaData);
HP=gethostbyname (HostNameIn c_str ());
Try {
IPAddress=inet_ntoa (* (struct in_addr *) HP - & gt; H_addr_list [ListNO]);
OutStr=IPAddress;
} the catch (... ) {
OutStr="";
}
WSACleanup ();
Return OutStr;
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
CodePudding user response:
Thank brothers back upstairs, I'll try ^_^