感谢!

解决方案 »

  1.   

    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>BOOL IsValidIP(char *strIP);
    int main()
    {
      char str[100];
      scanf("%s",str);
      if(IsValidIP(str)) printf("vliad IP");
        else  printf("invliad IP");
    }BOOL IsValidIP(char *strIP)
    {
      int ip0,ip1,ip2,ip3;
      sscanf(strIP,"%d.%d.%d.%d",&ip0,&ip1,&ip2,&ip3);
      if ((0<ip0&&ip0<255)&&(0<ip1&&ip1<255)
        &&(0<ip2&&ip2<255)&&(0<ip3&&ip3<255))
    return TRUE;
      return FALSE;
    }
      

  2.   

    An IP Address control, a control similar to an edit control, allows you to enter and manipulate a numerical address in Internet Protocol (IP) format. IP地址控件, 类似于编辑控件, 允许你输入和操作数字网络协议(IP)格式的地址。The CIPAddressCtrl class provides the functionality of the Windows common IP Address control. This control (and therefore the CIPAddressCtrl class) is available only to programs running under Microsoft Internet Explorer 4.0 and later. They will also be available under future versions of Windows and Windows NT.类CIPAddressCtrl 提供Windows 公用的IP地址控件的功能。该控件仅适用于Microsoft IE 4.0及其以后的版本上运行的程序。它也在Windows and Windows NT以上的版本有效。
      

  3.   

    用STRTOK分割后处理
    是否在FF - 0 区间中
      

  4.   

    unsigned long inet_addr (
      const char FAR * cp  
    );先使用inet_addr()分析,如果成功说明输入的就是一个合法的ip地址,如果返回INADDR_NONE则说明输入的是一个主机名,那么再使用gethostbyname()来获取其ip地址。我通常的做法是直接使用gethostbyname()来获得ip地址,发现虽然速度慢一点,但不管输入的是ip地址还是主机名该函数都能正确返回ip地址。
      

  5.   

    int MyGetHostIP(LPDWORD lpIP, LPDWORD lpMask)
    {
    WORD wVersionRequested = MAKEWORD(2, 2);
    WSADATA wsaData;
    if (WSAStartup(wVersionRequested, &wsaData) != 0) return 0;
    int nAdapter = 0;
    do
    {
    char szHostname[256];
    if ( gethostname(szHostname, sizeof(szHostname)) )  break;
    HOSTENT* pHostEnt = gethostbyname(szHostname);
    if (pHostEnt == NULL) break;
    if (pHostEnt->h_length != 4) break; while ( pHostEnt->h_addr_list[nAdapter] )
    {
    in_addr address;
    CopyMemory(&address.S_un.S_addr, pHostEnt->h_addr_list[nAdapter], pHostEnt->h_length);
    *(lpIP + nAdapter) = address.S_un.S_addr; if ( ++nAdapter >= 16 ) break;
    }
    } while(0);
    WSACleanup();
    return nAdapter;
    }