Mit C++ IP-Adresse ändern
-
Hallo,
Gibts es eine möglichkeit die IP-Adresse zur laufzeit mit c++ zu ändern?
Danke!!!

-
Die die du vom Provier bekommst?

-
Nein!!! Ich meine die lokale statische IP!!!! z.b von 192.168.1.106 auf --> 192.168.1.105

-
Mit Standard C++ Mitteln ist das nicht möglich. Wenn dann über irgend eine systemspezifische Lösung.
-
-
ja das habe ich auch schon gefunden aber VB kenne ich mich überhaupt net aus.
-
bin mir nicht sicher, aber ich glaueb sfml kann das
IPAddress Class Reference
IPAddress (const std::string &Address) Construct the address from a string. IPAddress (const char *Address) Construct the address from a C-style string ; Needed for implicit conversions from literal strings to IPAddress to work. IPAddress (Uint8 Byte0, Uint8 Byte1, Uint8 Byte2, Uint8 Byte3) Construct the address from 4 bytes. bool IsValid () const Tell if the address is a valid one.
-
super danke!!! Ich schau mir das mal an!!

-
David_pb schrieb:
Mit Standard C++ Mitteln ist das nicht möglich. Wenn dann über irgend eine systemspezifische Lösung.
Ich habe was gefunden und doch es geht mit Standard C++ Mitteln. Das zauberwort heisst "iphlpapi.h" damit kann man einiges richtung IP, Mac-Adresse machen.
Beispiel wenn einer sich dafür Interessiert:
#include <windows.h> #include <stdio.h> #include <ctype.h> #include <iphlpapi.h> void Usage(void) { printf("Usage: Ipchange [ -l ] [ -a -n<index id> -i<ip address> -m<subnet mask> ] " "[ -d -c<context id>]\n\n" "\t -l List adapter index IDs and IP Address context ID information\n" "\t -a Add IP Address option\n" "\t -d Delete IP Address option\n" "\t -i IP Address to specify with -a option\n" "\t -m Subnet Mask to specify with -a option\n" "\t -c IP context ID for an existing IP address\n" "\t -n Index ID of an existing network adapter\n"); } int main(int argc, char *argv[]) { ULONG NTEContext = 0; ULONG NTEInstance; IPAddr NewIP; IPAddr NewMask; DWORD Index; DWORD Context; CHAR NewIPStr[64]; CHAR NewMaskStr[64]; PIP_ADAPTER_INFO pAdapterInfo, pAdapt; PIP_ADDR_STRING pAddrStr; DWORD AdapterInfoSize; DWORD Err; BOOL OptList = FALSE; BOOL OptAdd = FALSE; BOOL OptDel = FALSE; NewIPStr[0] = '\0'; NewMaskStr[0] = '\0'; Context = 0; Index = 0; for (int i = 1; i < argc; i++) { if ((argv[i][0] == '-') || (argv[i][0] == '/')) { switch(tolower(argv[i][1])) { case 'l': OptList = TRUE; break; case 'a': OptAdd = TRUE; break; case 'c': if (strlen(argv[i]) > 2) Context = atoi(&argv[i][2]); break; case 'd': OptDel = TRUE; break; case 'i': if (strlen(argv[i]) > 2) strcpy(NewIPStr, &argv[i][2]); break; case 'm': if (strlen(argv[i]) > 2) strcpy(NewMaskStr, &argv[i][2]); break; case 'n': if (strlen(argv[i]) > 2) Index = atoi(&argv[i][2]); break; default: printf("default\n"); Usage(); return 0; } } else { printf("else\n"); Usage(); return 0; } } // Check options if ((OptAdd && (Index == -1 || NewIPStr[0] == '\0' || NewMaskStr[0] == '\0')) || (OptDel && Context == -1)) { Usage(); return 0; } // Get sizing information about all adapters AdapterInfoSize = 0; if ((Err = GetAdaptersInfo(NULL, &AdapterInfoSize)) != 0) { if (Err != ERROR_BUFFER_OVERFLOW) { printf("GetAdaptersInfo sizing failed with error %d\n", Err); return 0; } } // Allocate memory from sizing information if ((pAdapterInfo = (PIP_ADAPTER_INFO) GlobalAlloc(GPTR, AdapterInfoSize)) == NULL) { printf("Memory allocation error\n"); return 0; } // Get actual adapter information if ((Err = GetAdaptersInfo(pAdapterInfo, &AdapterInfoSize)) != 0) { printf("GetAdaptersInfo failed with error %d\n", Err); return 0; } if (OptList) { printf("MAC Address - Adapter\n" "Index Context Ip Address Subnet Mask\n" "--------------------------------------------------------------\n"); pAdapt = pAdapterInfo; while (pAdapt) { for (UINT i=0; i<pAdapt->AddressLength; i++) { if (i == (pAdapt->AddressLength - 1)) printf("%.2X - ",(int)pAdapt->Address[i]); else printf("%.2X-",(int)pAdapt->Address[i]); } printf("%s\n", pAdapt->Description); pAddrStr = &(pAdapt->IpAddressList); while(pAddrStr) { printf("%-10.d%-10.d%-20.20s%s\n", pAdapt->Index, pAddrStr->Context, pAddrStr->IpAddress.String, pAddrStr->IpMask.String); pAddrStr = pAddrStr->Next; } pAdapt = pAdapt->Next; } } if (OptAdd) { NewIP = inet_addr(NewIPStr); NewMask = inet_addr(NewMaskStr); if ((Err = AddIPAddress(NewIP, NewMask, Index, &NTEContext, &NTEInstance)) != 0) { printf("AddIPAddress failed with error %d, %d\n", NTEContext, Err); return 0; } } if (OptDel) { if ((Err = DeleteIPAddress(Context)) != 0) printf("DeleteIPAddress failed %d\n", Err); } return EXIT_SUCCESS; }Trozdem an alle vielen Dank!!!! :p
-
Ich habe was gefunden und doch es geht mit Standard C++ Mitteln.
Falsch, du hast die WinAPI benutzt, das zählt nicht zu den Standard C++ Mitteln.
-
OK OK!!

-
Dieser Thread wurde von Moderator/in evilissimo aus dem Forum C++ in das Forum WinAPI verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.