Monday, December 27, 2010

Calculator (C++)

#include "stdafx.h"
#include <iostream>
using namespace std;

void plus();
void minus(); 
void mult();     //Here are the declerations of the functions.
void dev();
void exit();


int main()
{
    int sth=0;
   
    while(1) //The while loop,will execute again and again the stuff below(but only code which is in it's scopes!)
    {
      cout << "Press 1 for Addition" << endl;
      cout << "Press 2 for Subtraction" << endl ;    //Here are the senteces about calculations..
      cout << "Press 3 for Multiplication" << endl;
      cout << "Press 4 for Devision" << endl ;
     


int choice;
    cin >> choice;
   
   
    switch (choice) //The switch statement,is like the if statement.It will run the cases below.
    {
   
case 1:
    choice = 1;
        cout << "->Addition\n";
                plus();
                    break;
   
   
   
case 2:
    choice = 2;
        cout << "->Subtraction\n";  
                minus();
                    break;



case 3:
    choice = 3;
        cout << "->Multiplication\n";  
                mult();
                    break;                   
   
   
   
   
case 4:
    choice = 4;
        cout << "->Devision\n";
                dev();
                    break;


}
continue; //Here the loop will stop and run again from the beginning.

}
       
    char f;
    cin >> f;
    return 0;

}


void plus()  //Here are the function's definitions.
{
    int my[2]; //The array here,will make 2 new integer variables,for later use.

    cout << "Put 1st number:  ";
   
    cin >> my[0]; //Int the 1st array here will be put the 1st number.
   
    cout << "Put 2nd number:  "  ;
   
    cout << endl;

    cin >> my[1]; //And here the 2nd.

    cout << "The result is : ";
   
    cout << my[0] + my[1] << endl; //This will print out the result.
   
    exit(); //And at the end the "exit" function will be called!

}

void minus()
{
   
    int my[2];

    cout << "Put 1st number:  ";
   
    cin >> my[0];
   
    cout << "Put 2nd number:  " << endl ;
   
    cin >> my[1];
   
    cout << "The difference is : ";
   
    cout << my[0] - my[1]<< endl ;

    exit();

}

void mult()
{
    int my[2];

    cout << "Put 1st number:  ";
   
    cin >> my[0];
   
    cout << "Put 2nd number:  " << endl ;
   
    cin >> my[1];
   
    cout << "The product is : ";
   
    cout << my[0] * my[1] << endl ;

    exit();

}

void dev()
{
    int my[2];

    cout << "Put 1st number:  ";
   
    cin >> my[0];
   
    cout << "Put 2nd number:  " << endl ;
   
    cin >> my[1];
   
    cout << "The quotient is : ";
   
    cout << my[0] / my[1] << endl;
   
    exit();

}                                                                           

void exit()
{
    cout << "                                                      Press 0 to Exit" << endl ;
   
    int quit;
            cin >> quit;
            if (quit == 0)
            {
            exit(0);
            }
 
}


Check open port (php)

 Hmm simply save it *.php
It will check n display opened ports

<html><head><title>Check Open Ports</title></head>
<body>
<center>
<br><br>
<h1>You IP is:<br><font color='blue'><?php echo $_SERVER['REMOTE_ADDR'];?></font></h1>
<br>
<form action="" method="post">
<h2>Enter ip adress to check: <h2><br><input type="text" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR'];?>" size="30"/><br><br>
<h2>Enter port to check: <h2><br><input type="text" name="port" size="20"/><br><br>
<input type="submit" value="check"/>
</form> 
</center>


<?php
$ip=$_POST["ip"];

$port = $_POST["port"];
if ($ip && $port){
$fp = @fsockopen($ip,$port,$errno,$errstr,5);
if(!$fp)
{
echo " <center><h3>Destination IP is <br><font color='blue'>".$ip."</font><br>Cannot connect to server  <br> Port <font color='red'>".$port." </font>is<br><h2> <b><font color='red'>Closed</b></h2></h3></center>";
}

else{
echo "<center><h3>Destination IP is <br><font color='blue'>".$ip."</font><br>Connect was successful <br> Port <font color='green'>".$port." </font> is<br><h2> <b><font color='green'>Open</b></h2></h3></center>";
fclose($fp);
}
}

?>
</body></html>


Sunday, December 26, 2010

How to close open port

So i've been looking for a while on just how to close a port on a computer. I simply
couldn't find a way. Well, i finally found it. This'll only work for windows users (unless
your unix version OS has netsh).
it's actually quite simple. here's the command for it:
netsh firewall delete portopening TCP portnumber

it's that simple. Simply go to START -> RUN -> and type in that command up there,
and it'll close it for you.
or, you can also open up command prompt (START -> RUN -> CMD) and type in "netsh"
without the quotes to get to your windows firewall settings.
however, since i'm such a nice guy, i wrote it all out in a vbs script for you so that it's
automatically runable. as well as a batch script. so here you are fellas:

.VBS Script
set ss = createobject("wscript.shell")
set ws = wscript
dim PORT
PORT = InputBox("Enter the port you wish to close:")
ss.run "netsh.exe"
ws.sleep 1000
ss.sendkeys "firewall delete portopening TCP " & PORT
ss.sendkeys "{enter}"
ws.sleep 500
'ss.sendkeys "exit"
'ss.sendkeys "{enter}"



.BAT Script
@echo off
title Port Closer
echo Port Closer
echo.
set /p port=Type the port number you wish to close here:
netsh firewall delete portopening TCP %port%
msg /w * Port %port% has been closed.
exit