C++ translation from python

I wrote a port scanner in python years ago and i'd like to start using it in C++ i just dont know how i can translate it from python to C++

Python code :

#!/usr/bin/env python

import socket
import subprocess
import sys
from datetime import datetime



def menu() :
print """

1)Find Ip
2)Port Scan
3)exit

"""
choices = raw_input("Please choose one of the following: ")

if choices == "1":
findIP()

if choices == "2" :
ipScan()

if choices == "3" :
exit()

def findIP() :
web_address = raw_input("Enter the name of the website you want a ip-address for: ")
if web_address == web_address :
subprocess.call(["nslookup", web_address])
choice = raw_input("would you like to go back to the menu? Y/N: ")
if choice == "y" :
menu()

else:
exit()

def ipScan() :

// clears the screen

subprocess.call("clear", shell = True)

// asks user for a Url
openports = []
remoteServer = raw_input("Enter a Ip-address to scan: ")
remoteServerIP = socket.gethostbyname(remoteServer)

// athestic use for a banner with the information inside : P
print "-" * 60
print "Please wait, scanning Webserver", remoteServerIP
print "-" * 60

// checks the time the scan started
t1 = datetime.now()

//in range specifies my ports and scans all ports between 1 and 1025

// error handling to make it robust by catching errors!!

try :
for port in range(1, 1025) :
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

result = sock.connect_ex((remoteServerIP, port))
if result == 0 :
print "port {}: \t Open".format(port)
openports.append(port)

sock.close()


else:
print "port %s shut" % (port)
pass


except KeyboardInterrupt :
print
print
print "You pressed Ctrl+C"
sys.exit()


except socket.gaierror:
print 'Hostname could not be resolved. Exiting'
sys.exit()


except socket.error :
print "Couldnt connect to server."
sys.exit()

// checks the time again
t2 = datetime.now()

//calcs the difference in time to see how long it took to run the scan
total = t2 - t1

// prints the information so we can see it
print "Scanning completed in: ", total
print "The Open Ports Are %s" % (openports)
versions = raw_input("Would you like the versions of the open ports? Y/N: ")
if versions == "y":
web_address = raw_input("Enter ip-address: ")
if web_address == web_address :
subprocess.call(["nmap", "-sSV", web_address])

else :
exit()

menu()

with a hardware tap and internet url stuff, its not going to translate so much as be a total rewrite, and it may depend on what OS you want to use it on what library you need to do those things.

your best bet is to reverse this back into requirements in English and then write a c++ program from those, rather than any sort of attempt to translate it.
Here's a skeleton to get you started:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>

using namespace std;

const int LOOKUP = 1;
const int SCAN  = 2;
const int EXIT = 3;

void show_menu();
int get_menu_choice();
void perform_lookup();
void perform_scan();

int main() 
{
  bool running = true;

  while(running)
  {
    show_menu();
    int choice = get_menu_choice();
    switch(choice)
    {
      case LOOKUP:
        perform_lookup();
        break;
      case SCAN:
        perform_scan();
        break;
      case EXIT:
        running = false;
        break;
      default:
        cout << "\a\nInvalid choice. Please try again.\n";
    }
  }
}

void show_menu()
{
}

int get_menu_choice()
{
  return EXIT;
}
void perform_lookup()
{
}
void perform_scan()
{
}


C++ doesn't know about ports and the net so you need to find some external library.
is this related to the other person's question or a new topic? I can't follow links @ work.
Topic archived. No new replies allowed.