Help, buged port scanner, can't find the bug :(
Ok, i was already asking for help here and i got pretty good one. Now i did all the gui, but logic isn't working. When i press the scan everything just stucks...
This is the class that does scanning.
package portscanner;
import UI.ResultPanel;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
public class Scanner {
private Socket sock = null;
private InetAddress hostip;
private String hostname = "127.0.0.1";
private ResultPanel rp = new ResultPanel();
public void Scanner(){
public void scan() {
try {
InetAddress addr = InetAddress.getByName(hostname);
rp.resultArea.append("Scanning started...");
rp.resultArea.repaint();
for (int i = 1; i < 65536; i++) {
try {
sock = new Socket(addr,i);
rp.resultArea.append("Port: " + i + "is open on " + addr);
rp.resultArea.repaint();
catch (IOException ex) {
finally {
try {
if (sock != null) sock.close();
catch (IOException ex) {}
} //for
} //try
catch (UnknownHostException ex) {
rp.resultArea.append("There has been an error. Aborting...");
rp.repaint();
public Socket getSock() {
return sock;
public void setSock(Socket sock) {
this.sock = sock;
public InetAddress getHostip() throws UnknownHostException {
return hostip;
public void setHostip(InetAddress hostip) {
this.hostip = hostip;
public ResultPanel getRp() {
return rp;
public void setRp(ResultPanel rp) {
this.rp = rp;
Class that does the UI.
package UI;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class UI extends JPanel{
ResultPanel sp = new ResultPanel();
private JLabel hostLabel = new JLabel("Host: ");
private JTextField hostField = new JTextField(20);
private JButton scanButton = new JButton("Scan");
private JButton quitButton = new JButton("Quit");
private JButton aboutButton = new JButton("About");
public UI(ActionListener al){
this.setLayout(new GridBagLayout());
setButtons(al);
fillPanel();
private void fillPanel(){
this.add(hostLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(5, 0, 0, 5), 0, 0));
this.add(hostField, new GridBagConstraints(1, 0, 20, 1, 0, 0,
GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL,
new Insets(5, 0, 0, 5), 0, 0));
this.add(scanButton, new GridBagConstraints(0, 1, 1, 1, 0, 0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(5, 0, 0, 5), 0, 0));
this.add(quitButton, new GridBagConstraints(1, 1, 1, 1, 0, 0,
GridBagConstraints.CENTER,
GridBagConstraints.NONE,
new Insets(5, 0, 0, 5), 0, 0));
this.add(aboutButton, new GridBagConstraints(2, 1, 1, 1, 0, 0,
GridBagConstraints.EAST,
GridBagConstraints.NONE,
new Insets(5, 0, 0, 5), 0, 0));
private void setButtons(ActionListener al){
scanButton.setActionCommand("scan");
scanButton.addActionListener(al);
scanButton.setMnemonic('S');
quitButton.setActionCommand("quit");
quitButton.addActionListener(al);
quitButton.setMnemonic('Q');
aboutButton.setActionCommand("about");
aboutButton.addActionListener(al);
aboutButton.setMnemonic('A');
public JLabel getHostLabel() {
return hostLabel;
public void setHostLabel(JLabel hostLabel) {
this.hostLabel = hostLabel;
public JTextField getHostField() {
return hostField;
public void setHostField(JTextField hostField) {
this.hostField = hostField;
public JButton getScanButton() {
return scanButton;
public void setScanButton(JButton scanButton) {
this.scanButton = scanButton;
public JButton getQuitButton() {
return quitButton;
public void setQuitButton(JButton quitButton) {
this.quitButton = quitButton;
public JButton getAboutButton() {
return aboutButton;
public void setAboutButton(JButton aboutButton) {
this.aboutButton = aboutButton;
This is the class that does result panel.
package UI;
import java.awt.*;
import javax.swing.*;
public class ResultPanel extends JPanel {
public JTextArea resultArea = new JTextArea(19, 20);
public JScrollPane resultScroll = new JScrollPane(resultArea);
public ResultPanel(){
this.setBackground(Color.LIGHT_GRAY);
this.add(resultScroll);
public JTextArea getResultArea() {
return resultArea;
public void setResultArea(JTextArea resultArea) {
this.resultArea = resultArea;
public JScrollPane getResultScroll() {
return resultScroll;
public void setResultScroll(JScrollPane resultScroll) {
this.resultScroll = resultScroll;
And the main...
package portscanner;
import UI.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;
public class Main extends JFrame implements ActionListener {
JPanel mainPanel = new JPanel(new BorderLayout());
Scanner sc = new Scanner();
ResultPanel rp = new ResultPanel();
UI window;
Socket s;
public Main() {
window = new UI(this);
window.setBackground(Color.LIGHT_GRAY);
mainPanel.add(window, BorderLayout.CENTER);
mainPanel.add(rp, BorderLayout.SOUTH);
this.setContentPane(mainPanel);
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(false);
JFrame mainWindow = new Main();
mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainWindow.setSize(300, 450);
mainWindow.setLocationRelativeTo(null);
mainWindow.setVisible(true);
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("scan")){
sc.scan();
if(e.getActionCommand().equals("quit")){
Please help :S
Try this. I'm not experienced with Threads, this is just my stab at it.
public class Scanner extends Thread {
public void run() {
scan();
private void scan() {
public class Main extends JFrame implements ActionListener {
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("scan")){
(new Scanner()).start();
if(e.getActionCommand().equals("quit")){
}
Similar Messages
-
I'm trying to draw icons over a background panel (with image). The icons are stored in an ArrayList, called listeJoueurs, more exactly, wrapped in custom 'Icone' objects with two fields, Point p and Image img (the icon itself).Here's the code where I create this :
public void paintComponent(Graphics g) {
super.paintComponent(g);
paintBckground(g);
// sprite(s)
ListIterator it = listeJoueurs.listIterator();
while (it.hasNext()) {
Icone image = (Icone) it.next();
Point p = (Point) image.p;
g.drawImage(image.img, p.x, p.y, this);
* Panel with image bckground
public void paintBckground(java.awt.Graphics g) {
int width = getWidth();
int height = getHeight();
java.awt.Color oldColor = g.getColor();
Dimension s = getSize();
if (isOpaque()) {
g.setColor(getBackground());
g.fillRect(0, 0, width, height);
// Le plateau en fond
try {
if (background != null) {
g.drawImage(background, 0, 0, (int) s.getWidth(), (int) s
.getHeight(), this);
} catch (Exception e) {
e.printStackTrace();
g.setColor(oldColor);
}Now, here's the method here I add an icon to the list :
public void addIcon(ImageIcon icon) {
startPoint.x -= 25; // startPoint defined as static int at the top of file
Icone i = new Icone(icon.getImage(), startPoint);
listeJoueurs.add(i);
repaint();
}Well, here's the bug now : I only get ONE icon displayed, whatever their real number is. I tried to test if the list contained several and it actually does, but ONE only is displayed...
Do you see something wrong in the code above ?>
Now, here's the method here I add an icon to the list
public void addIcon(ImageIcon icon) {
startPoint.x -= 25; // startPoint defined as static
int at the top of file
Icone i = new Icone(icon.getImage(), startPoint);
listeJoueurs.add(i);
repaint();
The problem is that you are using the same object, startPoint, for all the Icone instances.
Each time you change startPoint.x you are changing the x value for all Icone's. They are all being
drawn at the same location.
Point is a mutable class, changes any of its class members (x, y) are visible to anything that references the same Point instance.
You can do this
public void addIcon(ImageIcon img ) {
//** Change the static Point
startingPoint.x -= 25;
Point iconStart = new Point( startingPoint );
Icone i = new Icone( icon.getImage(), iconStart );
listeJouers.add( i );
repaint();
}to avoid the problem -
Help...where can i find the api for XSLTProcessor
Anyone can help me on tis....
i hav already
import org.apache.xalan.xslt.*;
to my program which look like tis
//program Simpletransform.java
//necessary import files
import org.apache.xalan.xslt.*;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.apache.xerces.parsers.DOMParser;
//Here we can load the given XML and XSL files,
//transform the XML and store it in the output file.
public class SimpleTransform {
public SimpleTransform(String xmlFile, String xslFile, String outFile) throws
java.io.IOException, java.net.MalformedURLException,
org.xml.sax.SAXException {
// Load the XSLT Processor.
XSLTProcessor xsltProc = new XSLTProcessorFactory.getProcessor();
// XSLTProcessor xsltProc = XSLTProcessorFactory.getProcessor();
xsltProc.process(new XSLTInputSource(xmlFile),
new XSLTInputSource(xslFile),
new XSLTResultTarget(outFile));
System.out.println("************* The result is in the " + outFile +
" file*************");
//method : main is for testing the program and just creates an instanceand tests the results.
public static void main(String[] args) {
try {
SimpleTransform st = new
SimpleTransform("example.xml", "example.xsl", "example.out");
catch (Exception e) {
System.out.println("Exception caught = " + e);
public SimpleTransform() {
but still there is error which look like tis
C:\A>javac -classpath C:\j2sdk1.4.2\lib\xerces.java;C:\j2sdk1.4.2\lib\xalan.jar
SimpleTransform.java
SimpleTransform.java:6: package org.apache.xerces.parsers does not exist
import org.apache.xerces.parsers.DOMParser;
^
SimpleTransform.java:19: cannot resolve symbol
symbol : class XSLTProcessor
location: class SimpleTransform
XSLTProcessor xsltProc = XSLTProcessorFactory.getProcessor();
^
SimpleTransform.java:19: cannot resolve symbol
symbol : variable XSLTProcessorFactory
location: class SimpleTransform
XSLTProcessor xsltProc = XSLTProcessorFactory.getProcessor();
^
SimpleTransform.java:22: cannot resolve symbol
symbol : class XSLTInputSource
location: class SimpleTransform
xsltProc.process(new XSLTInputSource(xmlFile),
^
SimpleTransform.java:23: cannot resolve symbol
symbol : class XSLTInputSource
location: class SimpleTransform
new XSLTInputSource(xslFile),
^
SimpleTransform.java:24: cannot resolve symbol
symbol : class XSLTResultTarget
location: class SimpleTransform
new XSLTResultTarget(outFile));
^
6 errors
CAn onyone help me???Thank youyou are using an older version of xalan, & the latest version of xalan.jar does not have these classes anymore. to transform the given xml, use the following code :
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
//Here we can load the given XML and XSL files,
//transform the XML and store it in the output file.
public class SimpleTransform
public SimpleTransform() throws TransformerException, FileNotFoundException
// Load the XSLT Processor.
TransformerFactory tFactory = TransformerFactory.newInstance();
Source xslSource = new StreamSource( "config/birds.xsl" );
Transformer transformer = tFactory.newTransformer( xslSource );
transformer.transform( new StreamSource("config/birds.xml"),new StreamResult( new FileOutputStream( "config/birds.out" )));
System.out.println("************* The result is in birds.out file*************");
//method : main is for testing the program and just creates an instanceand tests the results.
public static void main(String[] args)
try
SimpleTransform st=new SimpleTransform();
catch(Exception e)
System.out.println("Exception caught = " + e);
also, use the latest version of the xalan jar, which is xalan2.6.jar -
I must have clicked something, before I can see the design view, now I don't. How do I re - enable that?
Thanks.Please help me.... I tried to uninstall it and it is still doing the same thing... No Design View.. Please help me
-
Where can I find the bug database?
I was reading through the release notes for 2.4.16 and saw a reference to bug #16288 might have bearing on a problem I'm having. Would anyone know where I could find a detailed description of this bug? Also, if I find something that looks like a bug in the Berkeley DB XML, where would I send my report?
Hello,
Your problem is definitely [#16288] (see response on another thread). As Lauren said there is no publicly available bug database. Report them here and if you have a question about something from the changelog post that here as well, as you did.
Regards,
George -
Where can I find the System Mac 9 that would be in the (original release) factory shipped iMac's prior to 2010? I'm missing key system data and cannot update to iPhoto app past 6.0.6; any advice will be helpful, thank you.
Where can I find the System Mac 9 that would be in the (original release) factory shipped iMac's prior to 2010?
What are you refering to here? Mac OS 9 came out around 2001 ( or about ). Mac OS 9 last run in an emulation mode in 10.4.11 -- Tiger. Mac OS 9 ran on PPC machines that were last produced before 2004 or so.
I think your conclusion you need Mac OS 9 is incorrect.
I'm missing key system data and cannot update to iPhoto app past 6.0.6; any advice will be helpful, thank you.
iPhoto '11, Mac OS X (10.6.8), need to upgrade system to 10.8
We need to verify some information. Are you really running 10.6.8? What hardware?
Here is how to find out what version of Mac OS you are running:
Click on the blue apple in the upper left hand of the screen.
click on this icon
Click on the first line, "About This Mac"
Most of these are numbers & that's what we want.
What version & Processor do you have? -
Where can I find the song list for the glenn miller gold collection
Looking for help!!
Where can I find the song list for the CD of The Glenn Miller Gold Collection DIGITAL DEJAVU?
[email protected]Thank you for trying but this is the wrong disk. I'm looking for the list on the disk made in Italy by Phonocomp SpA . It has a number on it of 5-105-2 and CEDAR DIGITAL REMASTERING 1992DEJAVU.
I have tried to attach a picture of the disk but it will not paste to this reply.
Herbert Hamlin [email protected] -
I Have a Macbook Pro that does not have a disk drive. How do I install the Adobe Photoshop Elements 11 that came with the Epson scanner I purchased. I registered the S/N and I can't find the Free download anywhere only trials.
Downloads available:
Suites and Programs: CC 2014 | CC | CS6 | CS5.5 | CS5 | CS4 | CS3
Acrobat: XI, X | 9,8 | 9 standard
Premiere Elements: 13 | 12 | 11, 10 | 9, 8, 7
Photoshop Elements: 13 |12 | 11, 10 | 9,8,7
Lightroom: 5.7.1| 5 | 4 | 3
Captivate: 8 | 7 | 6 | 5
Contribute: CS5 | CS4, CS3
Download and installation help for Adobe links
Download and installation help for Prodesigntools links are listed on most linked pages. They are critical; especially steps 1, 2 and 3. If you click a link that does not have those steps listed, open a second window using the Lightroom 3 link to see those 'Important Instructions'. -
I downloaded the latest Facebook app ugrade to my iPad 2, and nowhere can i find the chat option. I also downloaded it to my iPhone4 and the chat option is there. Can somebody help me?
The first thing that has to be done with a new iPad is to activate it via iTunes. What version of iTunes, and what spec computer, have you got ? The iPad's minimum requirements are (from http://www.apple.com/ipad/specs/) :
Mac :
Mac computer with USB 2.0 port
Mac OS X v10.5.8 or later
iTunes 10.2 or later recommended
(free download from www.itunes.com/download)
iTunes Store account
Internet access
PC :
PC with USB 2.0 port
Windows 7; Windows Vista; or Windows XP Home or Professional with Service Pack 3 or later
iTunes 10.2 or later recommended
(free download from www.itunes.com/download)
iTunes Store account
Internet access
Edit : there is troubleshootin here :
pc - http://support.apple.com/kb/TS1538
mac - http://support.apple.com/kb/TS1591
Message was edited by: King_Penguin -
Help:Can not find the file in jar!
Hello everyone:
I build a project using Netbeans 5.0 and make a jar file with it...
The code in the project as follows will throw an exception described that it can not find the file named datasource-config.xml
String dataFilePath = getClass().getResource(dataFile).getPath();
//System.out.println("filepath:"+dataFilePath);
InputStream input = new FileInputStream(dataFilePath);
when I run the project with the main() function as an entry it works perfectly and output:
filepath:/C:/projects/java_project/search/build/classes/com/cn/wxjt/lucene/config/datasource-config.xml
But when I compressed the project with jar and run it , it will show:
filepath:file:/C:/projects/java_project/search/dist/search.jar!/com/cn/wxjt/lucene/config/datasource-config.xml
there is a (!) between search.jar and /com/cn/wxjt...
I dont know why I generate a ! symbol in the file path... Is it cause the exception->
java.io.FileNotFoundException: file:\C:\projects\java_project\search\dist\search.jar!\com\cn\wxjt\lucene\config\datasource-config.xml
If you have any idea, plz tell me.
Thank you and best wishes to you !
:)If the file you want to read is in your jar file, use
getClass ().getResourceAsStream
(relative_path_file_name)Hope that help,
Jackhey jack i want to open the file as new File
i m using this.getClass().getResource("resource/backend.xml");
the resource is the directory inside the jar file.
when i prints the url it shows:
the jar file is in the WORK directory
URL : jar:file:/home/neeraj/WORK/show.jar!/resource/backend.xml
now when i creates new File using the url.getFile() method the file does not exist.
although the same programs runs well when i uses the InputStream
so plz tell me cant I create a new File from the above method????
thanks in advance
with regards
neeraj -
Everytime I click a link that's not in the actual browser window, could be from a word doc, pdf-file or just plain info link in windows gadgets, I get an error:
[Clicked link]
Can't find the program
I have:
Windows 7 64-bit
Firefox 4 RC 1
Firefox is standard browser and installed at default location.
please help, it's getting really annoying!!This is what I get when opening a link from Outlook 2010.
Windows 7 64bit
Firefox 4 RC
Firefox 4 is set as the default browser
Links won't open in FF4 from any external programs (tweetdeck, outlook, word, etc.) -
I can't find the 2G, 3G and LTE options after updating to iOS8.1, can anyone help me with this? I'm using iPhone5s
I have check on my service provider about the correct APN settings, but unfortunately doesnt work still..
-
My MacBook Pro can't find the FireWire port
My MacBook Pro (OSX 10.6.8) can not find the FireWire port. Until now there hasn't been any problems using the FireWire, but now it just deny any knowledge of it, so to speak.
The audio device lights up when I connect it to the MBP (yes, I did connect it when in off-mode), so it seems to work in a way.
Does anyone recognize this problem and knows how to solve it?
/JohanLaMarHave you tried following through the trouble shooting tips in this knowledge base article on Firewire?
-
Hi,
We have just purchased Apple TV and can't connect to Home Sharing. We have wifi, the iPad is updated. I can't find the link on ITunes on the iPad that the tv is telling me to click. I've also tried turning it on via settings then music which seems to be connected. I can view YouTube clicks on the tv, but not an app so I can watch the footy. What am I doing wrong.
Any help would be greatly appreciated,
ThanksMake sure your Apple TV is on the same network as your iPad. The SSID and password of router must be set in your Apple TV.
http://i1224.photobucket.com/albums/ee374/Diavonex/491f4b34c45018abef609c832b0f2 56a_zps0d1c18e7.jpg
Message was edited by: Diavonex -
I have read the help info, but I can't find how to change the default email address, to the one that is my adobe I'd?
Adobe Reader for iOS doesn't set the default email address when you email a PDF.
It's found in the Settings app:
Settings > Mail, Contacts, Calendars > Mail > Default Account
Maybe you are looking for
-
Where does iPhone store contacts?
Hello, I will be in a different country for a few days and I will buy a SIM card from a different operator over there. Where does iPhone store contacts? Will my contacts stay on the phone with the new SIM card? Thank you.
-
Hi Gurus, The bank key used in IT 0009 is for employee bank account or for company bank account? Again if it is for company bank account, then while transferring employee from one company to another is it required to chnage the bank key? Regards, Vis
-
Is spell checking available in the Lightroom 5 Book Module?
-
Problem with creat PDF in adminui.
Hi, I have just install live cycle Pdf generator. installation log shows installation is successful.I have configure The things which I had to do,like installing windows office(2007),acrobat reader,change UAC. now when I want to convert some w
-
Install Flash Player in IE?
My Flash Player runs in FireFox fine, but not in IE on the same laptop. Do I need to install the Flash Player in IE, or should IE pick up Flash Player by itself?