블로그 이미지
fiadot_old

칼퇴근을 위한 게임 서버 개발 방법론에 대한 심도있는 고찰 및 성찰을 위한 블로그!

Rss feed Tistory
Technical Article/펌 2005. 9. 12. 10:19

IP가 고정인지' DHCP로 할당 된건지를 알 수 있는 방법

현재 IP가 고정인지' DHCP로 할당 된건지를 알 수 있는 방법 좀 갈켜 주십시...



Platform SDK 에 이에 관련된 소스가 있습니다.
작 성 자 황해수(proman2k) 첨 부
파 일
작성시각 2001-10-15 오후 12:44:01
조 회 수 493

저도 이것땜에 잠시나마 고민을 했었는데 간단하더군요.
오픈된 소스가 있으니....그냥 써버리면 되거든요.
허나..이에 대한 이해가 남달리 필요하겠지요.
아래 소스는 제가 제 프로그램에 맞게 수정한것입니다.
원 소스는 콘솔로 정보를 출력했거든요.
그리고 windows 2000에서만 되는걸로 알고 있습니다.
98이나 ME에선 아직 테스트는 못해봤습니다.

아래 소스에서 DHCP 부분에 YES 아니면 NO라는 값으로 DHCP의 사용 여부를 확인
할 수 있습니다.

수고하세요.

void CVirtualListView::OnButtonConfig()
{
// TODO: Add your command handler code here

CString IPConfigMSG; // Host Name
CString strpAddrStr; // second DNS Server
CString strNodeType; // Node Type
CString strpAdaptType; // Adatper Type
CString strAdapterName; // Adapter Name
CString strpAdaptDescription; // Adaptter Description
CString strpAdaptAddress; // MAC Address in Adapter ROM
CString strpAdaptDhcpEnabled; // DHCP Enable or Desable
CString strpAddrStrIpAddress; // Host"s IP Address
CString strpAddrStrIpMask; //Subnet Mask
CString strpAdaptGatewayList; // Default Gateway Address

CString strpAdaptDhcpServer; // DHCP Server is or not
CString strpAdaptPrimaryWinsServer; // Primary WINS Server
CString strpAdaptSecondaryWinsServer;// Secondary WINS Server


DWORD Err;

PFIXED_INFO pFixedInfo;
DWORD FixedInfoSize = 0;

PIP_ADAPTER_INFO pAdapterInfo, pAdapt;
DWORD AdapterInfoSize;
PIP_ADDR_STRING pAddrStr;

//
// Get the main IP configuration information for this machine using a FIXED_INFO structure
//
if ((Err = GetNetworkParams(NULL, &FixedInfoSize)) != 0)
{
if (Err != ERROR_BUFFER_OVERFLOW)
{
AfxMessageBox("GetNetworkParams sizing failed with error %d\n", Err);
return;
}
}

// Allocate memory from sizing information
if ((pFixedInfo = (PFIXED_INFO) GlobalAlloc(GPTR, FixedInfoSize)) == NULL)
{
AfxMessageBox("Memory allocation error\n");
return;
}

if ((Err = GetNetworkParams(pFixedInfo, &FixedInfoSize)) == 0)
{

//AfxMessageBox(pFixedInfo->HostName);

/*////////////////// Must to Print Message and Values /////////////////*/
//printf("\tHost Name . . . . . . . . . : %s\n", pFixedInfo->HostName);
//printf("\tDNS Servers . . . . . . . . : %s\n", pFixedInfo-
>DnsServerList.IpAddress.String);
//pAddrStr = pFixedInfo->DnsServerList.Next;

IPConfigMSG += pFixedInfo->HostName;

/*
while(pAddrStr)
{
strpAddrStr = pAddrStr->IpAddress.String;
//printf("%52s\n", pAddrStr->IpAddress.String);
pAddrStr = pAddrStr->Next;
}
*/

switch (pFixedInfo->NodeType)
{
case 1:
strNodeType = "Broadcast";
break;
case 2:
strNodeType = "Peer to peer";
break;
case 4:
strNodeType = "Mixed";
break;
case 8:
strNodeType = "Hybrid";
break;
default:
strNodeType = "\n";
}

} else
{
AfxMessageBox ("GetNetworkParams failed with error :" + Err);
return;
}

//
// Enumerate all of the adapter specific information using the IP_ADAPTER_INFO structure.
// Note: IP_ADAPTER_INFO contains a linked list of adapter entries.
//
AdapterInfoSize = 0;
if ((Err = GetAdaptersInfo(NULL, &AdapterInfoSize)) != 0)
{
if (Err != ERROR_BUFFER_OVERFLOW)
{
AfxMessageBox("GetAdaptersInfo sizing failed with error : " + Err);
return;
}
}

// Allocate memory from sizing information
if ((pAdapterInfo = (PIP_ADAPTER_INFO) GlobalAlloc(GPTR, AdapterInfoSize)) == NULL)
{
AfxMessageBox("Memory allocation error\n");
return;
}

// Get actual adapter information
if ((Err = GetAdaptersInfo(pAdapterInfo, &AdapterInfoSize)) != 0)
{
AfxMessageBox("GetAdaptersInfo failed with error %d\n", Err);
return;
}

pAdapt = pAdapterInfo;

while (pAdapt)
{
switch (pAdapt->Type)
{
case MIB_IF_TYPE_ETHERNET:
strpAdaptType = "Ethernet adapter";
break;
case MIB_IF_TYPE_TOKENRING:
strpAdaptType = "Token Ring adapter";
break;
case MIB_IF_TYPE_FDDI:
strpAdaptType = "FDDI adapter";
break;
case MIB_IF_TYPE_PPP:
strpAdaptType = "PPP adapter";
break;
case MIB_IF_TYPE_LOOPBACK:
strpAdaptType = "Loopback adapter";
break;
case MIB_IF_TYPE_SLIP:
strpAdaptType = "Slip adapter";
break;
case MIB_IF_TYPE_OTHER:
default:
strpAdaptType = "Other adapter";
}

strAdapterName = pAdapt->AdapterName;

strpAdaptDescription = pAdapt->Description;

CString imsi;

for (UINT i=0; i < pAdapt->AddressLength; i++)
{
if (i == 5)
{
imsi.Format("%02X",(int)pAdapt->Address[i]);
strpAdaptAddress += imsi;
}
else
{
imsi.Format("%02X-",(int)pAdapt->Address[i]);
strpAdaptAddress += imsi;
}
}

strpAdaptDhcpEnabled = pAdapt->DhcpEnabled ? "yes" : "no";

pAddrStr = &(pAdapt->IpAddressList);
while(pAddrStr)
{
strpAddrStrIpAddress = pAddrStr->IpAddress.String;
strpAddrStrIpMask = pAddrStr->IpMask.String;
pAddrStr = pAddrStr->Next;
}

strpAdaptGatewayList = pAdapt->GatewayList.IpAddress.String;
pAddrStr = pAdapt->GatewayList.Next;

while(pAddrStr)
{
pAddrStr->IpAddress.String;
pAddrStr = pAddrStr->Next;
}

strpAdaptDhcpServer = pAdapt->DhcpServer.IpAddress.String;
strpAdaptPrimaryWinsServer = pAdapt->PrimaryWinsServer.IpAddress.String;
strpAdaptSecondaryWinsServer = pAdapt->SecondaryWinsServer.IpAddress.String;


/*
struct tm *newtime;

// Display coordinated universal time - GMT
newtime = gmtime(&pAdapt->LeaseObtained);
printf( "\tLease Obtained. . . . . . . : %s", asctime( newtime ) );

newtime = gmtime(&pAdapt->LeaseExpires);
printf( "\tLease Expires . . . . . . . : %s", asctime( newtime ) );
*/ // 이부분은 제게 필요 없어서 주석처리 한것입니다. 필요하시면 사용하세요.
pAdapt = pAdapt->Next;

}
CPickTableDlg *dlg = new CPickTableDlg;
dlg->DoModal();

}







IP Changer

라입
IPHlpAPI.lib


/////////////////////////////
// IP Helper Function Header
// IPHlpAPI.lib을 쓴다.
#include
/////////////////////////////
,
TOTAL TODAY