To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Code Critique

Code Critique Having someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.

Reply
 
Thread Tools Rate Thread Display Modes
Old 10-19-2003, 12:26 AM   #1
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
Port Scanning

I was bored tonight so I wrote up a little port scanner in php. Took me less then an hour and the file is under 120 lines of code including comments, html and white space. On top of that it's valid xhtml.

Sometimes the simplicity of this language scares me. Anyway here it is, phport scanner.

This is educational software and not intended to be used for hacking or any other illegal activity.
Attached Files
File Type: zip port_scan.zip (1.7 KB, 145 views)
drawmack is offline   Reply With Quote
Old 10-19-2003, 03:41 AM   #2
HalfaBee
Not very lazy.
 
Join Date: Jun 2003
Location: Sydney, Australia
Posts: 1,851
Might be valid xhtml, but $_POST[ip] is not valid PHP.

HalfaBee
__________________
The lazy man always finds the best way!
Q: Who invented the auto-pilot?
A: The lazy pilot!
HalfaBee is offline   Reply With Quote
Old 10-19-2003, 04:17 AM   #3
laserlight
PHP Witch
 
laserlight's Avatar
 
Join Date: Apr 2003
Location: Singapore
Posts: 12,388
Invalid English comments too, with "at the end of teh form"

There's also $_POST[scan_btn], I think, though I doubt scan_btn will ever be a reserved word in PHP.

Actually, could there be a slight problem with your "if the person entered an ip resolve it to the domain name" regex?

Cos it doesnt seem to take into account that a domain name contains periods (and dashes) as well.
__________________
Use Bazaar for your version control system
Read the PHP Spellbook
Learn How To Ask Questions The Smart Way
laserlight is online now   Reply With Quote
Old 10-19-2003, 04:33 AM   #4
HalfaBee
Not very lazy.
 
Join Date: Jun 2003
Location: Sydney, Australia
Posts: 1,851
I saw the 'teh', but didn't think I would comment.
Hell, I can think 2000 WPM and ytpe 20.

Halfabee
__________________
The lazy man always finds the best way!
Q: Who invented the auto-pilot?
A: The lazy pilot!
HalfaBee is offline   Reply With Quote
Old 10-19-2003, 08:55 AM   #5
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
Quote:
Originally posted by laserlight
Invalid English comments too, with "at the end of teh form"

There's also $_POST[scan_btn], I think, though I doubt scan_btn will ever be a reserved word in PHP.

Actually, could there be a slight problem with your "if the person entered an ip resolve it to the domain name" regex?

Cos it doesnt seem to take into account that a domain name contains periods (and dashes) as well.
Yeah I guess I should quote my array indecies. What I do with the regex is say if it has letters, any letters, then it's a domain name otherwise it's an ip address. It's a very loose check but I was writting as an example of how easy port scans are in php.
drawmack is offline   Reply With Quote
Old 10-19-2003, 09:51 AM   #6
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
alright here is an updated version.

Change Log:
1) fixed spelling error in comment so that laserlight can stop twitching

2) quoted array index references that are not variables

3) put output into a table and used just a touch of css for readability.

4) did a bit better preperation on the input destination.

5) made http check port 80 instead of 115, don't know what I was thinking last night.

here it is
Attached Files
File Type: zip port_scan.zip (2.0 KB, 111 views)
drawmack is offline   Reply With Quote
Old 10-19-2003, 02:17 PM   #7
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
i'd say id works........ and its not hard to add to.

however it would be nice to have a 'check all' button.............
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Old 10-19-2003, 05:38 PM   #8
axo
idiotic member
 
Join Date: May 2003
Location: berlin
Posts: 100
eurgh... i get notices all over because of undefined variables, so:

replace line 50 with
Code:
<td colspan="4"><input type="text" size="30" name="ip" value="<?php echo isset($_POST['ip']) ? $_POST['ip'] : ""; ?>" /></td>
and replace line 64 with
Code:
    echo (isset($_POST[$cur_field]) && '1' == $_POST[$cur_field]) ? "checked " : "";
__________________
...
axo is offline   Reply With Quote
Old 10-19-2003, 05:46 PM   #9
axo
idiotic member
 
Join Date: May 2003
Location: berlin
Posts: 100
here's the modified version with the checkAll javascript function
Attached Files
File Type: zip port_scan.zip (2.3 KB, 129 views)
__________________
...
axo is offline   Reply With Quote
Old 10-19-2003, 08:16 PM   #10
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
one thing of note......... the current timeout limit of 10 allows for only two full timeouts... not enough time to check all ports. If there are too mny failures, the script itself wil timeout after 30 seconds. if you're goign to use this, timeout=3 and set_time_limit(0); wouldnt be a bad idea.
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Old 10-19-2003, 09:13 PM   #11
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
moon,
you make a good point, however I wrote it for educational purposes so I don't think I'll be adding code that makes it more usable.
drawmack is offline   Reply With Quote
Old 10-19-2003, 09:23 PM   #12
HalfaBee
Not very lazy.
 
Join Date: Jun 2003
Location: Sydney, Australia
Posts: 1,851
Quote:
Originally posted by Moonglobe
one thing of note......... the current timeout limit of 10 allows for only two full timeouts... not enough time to check all ports. If there are too mny failures, the script itself wil timeout after 30 seconds. if you're goign to use this, timeout=3 and set_time_limit(0); wouldnt be a bad idea.
I don't think time spent in these functions affects the script running time.

Halfabee
__________________
The lazy man always finds the best way!
Q: Who invented the auto-pilot?
A: The lazy pilot!
HalfaBee is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 12:49 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.