Advertisement
metalni

BanIP [C++]

Oct 29th, 2020 (edited)
2,213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. // A utillity program that takes ip addresses from input and transforms them into a linux command to drop them from iptables.
  2.  
  3. #include <iostream>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. class ipAddress{
  9.     private:
  10.         char ip[20];
  11.     public:
  12.         ipAddress(){
  13.             strcpy(this->ip, "127.0.0");
  14.         }
  15.  
  16.         ipAddress(char * ip){
  17.             strcpy(this->ip, ip);
  18.         }
  19.  
  20.         const char * getIpAddress(){
  21.             return this->ip;
  22.         }
  23.  
  24.         const void setIp(const char * ip){
  25.             strcpy(this->ip, ip);
  26.         }
  27. };
  28.  
  29. int main(void){
  30.     int n;
  31.     cin >> n;
  32.     ipAddress ips[n];
  33.    
  34.     for(int i=0; i<n; i++){
  35.         char tmp[20];
  36.         cin >> tmp;
  37.         ips[i].setIp(tmp);
  38.     }
  39.  
  40.     for(int i=0; i<n; i++)
  41.         cout << "iptables -A INPUT -s " << ips[i].getIpAddress() << " -j DROP\n";
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement