LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-18-2007, 06:32 PM   #1
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Rep: Reputation: 32
writing linux port scanner


Hi,

I'm trying to write a port scanner in C for Linux, can any one provide me with a bit of simple port scanner code which can help me? Cause I'm very new to Linux programming and I don't know where to start so a bit of code will be a great help.

regards,
Imran
 
Old 07-18-2007, 07:13 PM   #2
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
Far as I know its the same as in the windows world when you use sockets.


But I don't have enough experience with this sort of thing maybe someone else here can give you a little more.
 
Old 07-18-2007, 07:16 PM   #3
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Original Poster
Rep: Reputation: 32
the thing is that I'm not a professional programmer so if someone can provide me the code or can help me in any other way in terms of linux then it would be really very helpful for me.

regards
Imran
 
Old 07-18-2007, 07:16 PM   #4
Tux-Slack
Member
 
Registered: Nov 2006
Location: Slovenia
Distribution: Slackware 13.37
Posts: 511

Rep: Reputation: 37
nmap or Network Mapper is some sort of a port scanner
http://insecure.org/nmap/
And comes with source.
 
Old 07-19-2007, 06:44 PM   #5
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Original Poster
Rep: Reputation: 32
I've seen the code of nmap but that's to complex isn't there a simple port scanner code? which I can look at except nmap.

thank you

regards,
Imran
 
Old 07-19-2007, 07:39 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
this is a very very simple port scanner snippet in Python i use to monitor open ports.
Code:
import socket
remote_host="localhost"
for remote_port in [22,901,139]:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(60)
        try:
                sock.connect((remote_host, remote_port))
        except Exception,e:
                print "%d closed " % remote_port                
        else: 
                print "%d open" % remote_port
        sock.close()
you can basically do the same in C. As you can see, you have to learn how to code sockets in C.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
best port scanner To scan open port in a network tanveer Linux - Security 8 01-21-2007 08:19 PM
port scanner and more ANU Linux - Software 1 05-26-2006 09:53 AM
writing a port scanner in C hubabuba Programming 4 10-04-2005 07:38 PM
Port scanner alon005 Linux - Security 1 10-14-2004 11:20 PM
In need of the best port scanner there is! Pcghost Linux - Security 11 03-10-2003 09:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration