Advertisement
OriHackingTutorials

IP updater

Jun 17th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     std::cout << "\n    Finding your Ipv4 address... \n\n";
  11.     system("ipconfig | findstr IPv4 > ipconfigOutput.txt");
  12.  
  13.     std::ifstream ipconfigOutput("ipconfigOutput.txt");
  14.     std::string tempIpconfigOutput;
  15.     string finalIpOutput = "";
  16.     string onlyIp;
  17.     while (ipconfigOutput >> tempIpconfigOutput) {     
  18.         finalIpOutput += tempIpconfigOutput;       
  19.     }
  20.     ipconfigOutput.close();
  21.     system("del ipconfigOutput.txt");
  22.     // get only the IP.
  23.     onlyIp = finalIpOutput.substr(23, finalIpOutput.size() - 23);
  24.  
  25.     std::cout << "    Your IP is: " << onlyIp << "\n\n\n    Checking the IP in your \"server.properties\" file...\n\n";
  26.  
  27.     // check for the ip in server.properties file  
  28.     ifstream serverProperties("server.properties");
  29.     if (!serverProperties) exit(EXIT_FAILURE);
  30.     string tempServerOutput;
  31.     string finalServerOutput = "";
  32.     string onlyServerIp = "";
  33.     while (serverProperties >> tempServerOutput) {
  34.         if (tempServerOutput.substr(0, 9) == "server-ip")
  35.             finalServerOutput = tempServerOutput;      
  36.     }  
  37.     serverProperties.close(); // close the file.
  38.  
  39.     onlyServerIp = finalServerOutput.substr(10, finalServerOutput.size() - 10); // get only the IP itself. 
  40.    
  41.     cout << "    The IP in your server.properties is: " << onlyServerIp << "\n\n\n";
  42.  
  43.     if (onlyIp == onlyServerIp) { // if they are the same, nothing is needed to be changed.
  44.         cout << "    Your server.properties and your local IP address are the same. you dont need to do anything. goodbye!\n";
  45.         cout << " Press Any Key To Exit.";
  46.         system("pause >nul");
  47.         exit(EXIT_SUCCESS);
  48.     }
  49.  
  50.     //if they aint the same...
  51.     cout << "    Whoopsie! your local ip address and your server.properties one are NOT the same.\n";
  52.     cout << "    This could be a problem. Would you like me to fix that for you? (Y/n): ";
  53.     char answer;
  54.     cin >> answer;
  55.     if (answer == 'N' || answer == 'n') {
  56.         cout << "    You can fix it manually then. just open your \"server.properties\" file and change it.\n";
  57.         cout << "Press Any Key To Exit...\n";
  58.         system("pause >nul");
  59.         exit(EXIT_SUCCESS);
  60.     }
  61.     cout << "    Great. I will fix it now.\n"; 
  62.  
  63.     ofstream newServerP("server.properties", ios::app);
  64.     newServerP << "server-ip=" << onlyIp << '\n';  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement