Ip change



  • gibt es eine möglcihkeit in c++
    die ip zu ändern????



  • ipman schrieb:

    gibt es eine möglcihkeit in c++
    die ip zu ändern????

    Welche? Die vom Mond?

    Standard-C++ kennt weder Netzwerke noch IP-Adressen. Welches BS, welchen Compiler und welche Klassenbibliothek verwendest du?



  • WinAPI FORUM!!!



  • Tc++H schrieb:

    WinAPI FORUM!!!

    Ich habe letztens von nem Freund einer Bekannten gehört, dass es angeblich noch andere Betriebsysteme außer Windows geben soll 🙄

    Aus diesem Grund werde ich mit dem Verschieben noch warten, trotz deines Gebrülls 😉



  • Hier mal zwei Mezhoden aus der MSDN:

    für(Windows)

    DeleteIPAddress(ULONG NTEContext)
    
    AddIPAdress( IPAddr Address,
      IPMask IpMask,
      DWORD IfIndex,
      PULONG NTEContext,
      PULONG NTEInstance)
    
    // Before calling AddIPAddress we use GetIpAddrTable to get
    // an adapter to which we can add the IP.
    PMIB_IPADDRTABLE pIPAddrTable;
    DWORD dwSize = 0;
    
    pIPAddrTable = (MIB_IPADDRTABLE*) malloc( sizeof( MIB_IPADDRTABLE) );
    
    // Make an initial call to GetIpAddrTable to get the
    // necessary size into the dwSize variable
    if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
      GlobalFree( pIPAddrTable );
      pIPAddrTable = (MIB_IPADDRTABLE *) malloc ( dwSize );
    }
    
    // Make a second call to GetIpAddrTable to get the
    // actual data we want
    if ( (dwRetVal = GetIpAddrTable( pIPAddrTable, &dwSize, 0 )) == NO_ERROR ) { 
      printf("\tAddress: %ld\n", pIPAddrTable->table[0].dwAddr);
      printf("\tMask:    %ld\n", pIPAddrTable->table[0].dwMask);
      printf("\tIndex:   %ld\n", pIPAddrTable->table[0].dwIndex);
      printf("\tBCast:   %ld\n", pIPAddrTable->table[0].dwBCastAddr);
      printf("\tReasm:   %ld\n", pIPAddrTable->table[0].dwReasmSize);
    }
    else {
      printf("Call to GetIpAddrTable failed.\n");
    }
    
    // IP and mask we will be adding
    UINT iaIPAddress;
    UINT imIPMask;
    
    iaIPAddress = inet_addr("192.168.0.27");
    imIPMask = inet_addr("255.255.255.0");
    
    // Variables where handles to the added IP will be returned
    ULONG NTEContext = 0;
    ULONG NTEInstance = 0;
    
    if ( (dwRetVal = AddIPAddress(iaIPAddress, 
      imIPMask, 
      pIPAddrTable->table[0].dwIndex, 
      &NTEContext, 
      &NTEInstance) ) == NO_ERROR) {
      printf("\tIP address added.\n");
    }
    
    else {
      printf("Error adding IP address.\n");
    
      LPVOID lpMsgBuf;
      if (FormatMessage( 
        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
        FORMAT_MESSAGE_FROM_SYSTEM | 
        FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        dwRetVal,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
        (LPTSTR) &lpMsgBuf,
        0,
        NULL )) {
        printf("\tError: %s", lpMsgBuf);
      }
      LocalFree( lpMsgBuf );
    }
    
    // Delete the IP we just added using the NTEContext
    // variable where the handle was returned	
    if ((dwRetVal = DeleteIPAddress(NTEContext)) == NO_ERROR) {
      printf("\tIP Address Deleted.\n");
    }
    else {		
      printf("\tCall to DeleteIPAddress failed.\n");
    }
    

Anmelden zum Antworten