Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » Cant connect but dont get an error
Cant connect but dont get an error [message #39500] Sat, 23 March 2013 16:03 Go to previous message
Brat is currently offline  Brat
Messages: 7
Registered: March 2013
Promising Member
Hello,
sorry for my bad english, i'm from germany.

I want to check whether a port is open or not.

Here is my code:

main.cpp
#include "PortScan.h"
using namespace Upp;
PortScan::PortScan() {
	CtrlLayout(*this, "Simple Portscanner");
	InBtnScan <<= THISBACK(Button);
}

void PortScan::Button(){
	int sPort 	= InStartPort;
	int ePort 	= InEndPort;
	String url 	= InStrUrl;
	TcpSocket socket;
	
	
	socket.Connect(url, sPort);
	socket.Timeout(200);
	
	if(!socket.IsError()){
		PromptOK("Port is open");
	}
	
	socket.Close();
}

GUI_APP_MAIN {
	PortScan().Run();
}


PortScan.h
#ifndef _PortScan_PortScan_h
#define _PortScan_PortScan_h

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#define LAYOUTFILE <PortScan/PortScan.lay>
#include <CtrlCore/lay.h>

class PortScan : public WithPortScanLayout<TopWindow> {
	public:
		typedef PortScan CLASSNAME;
		PortScan();
		void Button();
};

#endif


PortScan.lay
LAYOUT(PortScanLayout, 524, 152)
	ITEM(EditInt, InStartPort, HSizePosZ(68, 212).TopPosZ(80, 19))
	ITEM(EditInt, InEndPort, LeftPosZ(68, 244).TopPosZ(104, 19))
	ITEM(EditString, InStrUrl, LeftPosZ(68, 244).TopPosZ(56, 19))
	ITEM(Label, dv___3, SetLabel(t_("URL")).LeftPosZ(4, 56).TopPosZ(56, 20))
	ITEM(Label, dv___4, SetLabel(t_("Start Port")).LeftPosZ(4, 56).TopPosZ(80, 20))
	ITEM(Label, dv___5, SetLabel(t_("End Port")).LeftPosZ(4, 56).TopPosZ(104, 20))
	ITEM(Button, InBtnScan, SetLabel(t_("Scan")).LeftPosZ(4, 56).TopPosZ(132, 15))
END_LAYOUT

The URL Input field defines the host, Start Port defines the Port to check. End Port isnt used yet (Want to create a simple Portscanner).

I compiled and tested my program under OpenSuSE 12.1
uname -a:
Linux linux-m3d8.site 3.1.10-1.16-desktop #1 SMP PREEMPT Wed Jun 27 05:21:40 UTC 2012 (d016078) x86_64 x86_64 x86_64 GNU/Linux


The program compiles without an error, but it says every port on every host is open. How can i change this? I allready tryed to use "if(socket.IsOpen())" - but this didnt change anything.

[Updated on: Sat, 23 March 2013 16:04]

Report message to a moderator

 
Read Message
Read Message
Read Message
Previous Topic: How to call a C++ function in Witz template?
Next Topic: Witz internationalization
Goto Forum:
  


Current Time: Wed Jun 05 14:02:42 CEST 2024

Total time taken to generate the page: 0.01902 seconds