Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 21st, 2004, 5:43 PM   #1
Beegie_B
Programmer
 
Join Date: Nov 2004
Location: Windsor, Ontario, Canada
Posts: 32
Rep Power: 0 Beegie_B is on a distinguished road
Send a message via ICQ to Beegie_B Send a message via MSN to Beegie_B
On my spare time 2 years back I decided to write a IP scanner program... this never got off it's feet really, but I did get it to work (somewhat)... I'd say it's best for Windows since it's the only platform I acctually tested it on. It's really buggy, and yah... if you want to scan IP ranges, don't use this! Heh

#Beegie_B's IP Scanner v0.4 BETA 
#Scans IP's to see if they are online 
#Now Supports Ranges
#If you want to copy this program and distribute it please give reference to me.
#This program can be used freely by anyone
import os
from os import mkdir, rmdir, remove, chdir
from time import time, ctime
from socket import *

print """ 
  This is the BETA version of my IP scanner. Minor bugs were found
  in the scanner when used on Windows XP.
  Please report all bugs and improvement codes to: 
  webmaster@bastardshandbook.com.
  I need some people who can test this on Linux, Unix, and Mac for me.
  
  Creator: Beegie_B 
  Date: Mar 2, 2004 
  Version: 0.4 BETA 
  Tested On: Windows XP
  Changes Since v0.3 BETA: run change() to view
  ================================================================= 
  Run man() for help on use of the IP scanner. 
  """ 

def ipScan(ipStart, ipEnd, r): #r = range
  logWrite = "txt_logs/%s.txt" %(str(ctime(time())[0:10])) #This will make the log title the Date
  x = 3
  logHold = []
  for s in r:
    hold = [ipStart[0],ipStart[1],ipStart[2],ipStart[3]] #This will hold theorgiginal IP
    while int(ipStart[x]) <= int(ipEnd[x]) and int(ipStart[3]) <= int(ipEnd[3]):
      s = ipStart
      ipStart = ".".join(ipStart)
      scn = os.system("ping " + ipStart + " -w .1 -n 1") #-w = timeout, -n = number of scans
      if scn >= 0 and scn < 1: 
        print ipStart,": Online"
        logHold.append(ipStart + "\t" + gethostbyaddr(ipStart)[0] + "\tOnline")
      elif scn >= 1:
        print ipStart,": Offline"
        logHold.append(ipStart + "\t" + gethostbyaddr(ipStart)[0] + "\tOffline")
        #gethostbyaddr gets host name by putting in the IP address
      ipStart = s
      s = ipStart[3]
      s = int(s)
      s = s + 1
      s = str(s)
      ipStart[3] = s
    p = 0
    for k in hold: #Resets the original IP for further scanning
      ipStart[p] = hold[p]
      p = p + 1
    x = x-1
    n = int(ipStart[x]) + 1
    ipStart[x] = str(n)
    #str() converts to string, int() converts to integer
  logInfoHeader = "IP Address\tHost Name\t\t\tStatus"
  logInfo = "\n".join(logHold) #Joins all the log info into a string
  logInfo = "Scan Date: " + str(ctime(time())) + "\n\n" + logInfoHeader + "\n\n" + logInfo + "\n\n"
  try: #Will make a logs directory
    mkdir("logs")
    chdir("logs")
    mkdir("txt_logs")
    w = open(logWrite, "ar").write(logInfo) #Writes Log and saves as log.txt
  except OSError: #If the directory is made it will bypass making one
    try:
      chdir("logs")
      mkdir("txt_logs")
      w = open(logWrite, "ar").write(logInfo) #Writes Log and saves as log.txt
    except OSError:
      w = open(logWrite, "ar").write(logInfo) #Writes Log and saves as log.txt

def scanIP(): 
  ipStart = raw_input("IP Start: ")
  ipEnd = raw_input("IP End: ")
  ipStart = ipStart + "."
  ipEnd = ipEnd + "."
  h = x = 0
  rangeStart = []
  rangeEnd = []
  rangeDiff = []

  while len(rangeStart) < 4: #Grabs the IP address numbers without the "." for ipStart
    while ipStart[x] != ".":
      x = x+1
    rangeStart.append(ipStart[h:x])
    x = x+1
    h = x

  h = x = 0

  while len(rangeEnd) < 4: #Grabs the IP address numbers without the "." for ipEnd
    while ipEnd[x] != ".":
      x = x+1
    rangeEnd.append(ipEnd[h:x])
    x = x+1
    h = x

  x = 0
  
  for s in rangeStart: #Finds the range
    p = int(rangeStart[x])
    o = int(rangeEnd[x])
    rangeDiff.append(o-p)
    if rangeDiff[x] < 0:
      print "Invalid Range, Try Again"
      s = 4
    x = x+1
  if s == 4:
    pass
  else:
    ipScan(rangeStart, rangeEnd, rangeDiff) #Does the IP scan

def man(): 
  print """ 
  To run use the command scanIP() 
  The IP scanner is only tested on Windows XP but I belive it should 
  work on different OS's also. 
  When running the program make sure not to close the window that 
  gets oppend. Like I said, the scanner is only tested on Windows XP 
  and CMD will automatically close by itself. 
  """

def change():
  print """
  Changes since v0.3 BETA are:

  1. Now automatically logs the scan
  2. Hostname info is included in the log

  NOTE: An HTML View of the log will be added in the next version
  """

Have fun lookin at it

Beeg
Beegie_B is offline   Reply With Quote
Old Nov 22nd, 2004, 9:09 AM   #2
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Hey, isn't this the same as this->this?
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Nov 22nd, 2004, 11:02 AM   #3
Beegie_B
Programmer
 
Join Date: Nov 2004
Location: Windsor, Ontario, Canada
Posts: 32
Rep Power: 0 Beegie_B is on a distinguished road
Send a message via ICQ to Beegie_B Send a message via MSN to Beegie_B
Nope, Ones a IP Range Scanner, and the Other is a Port Scanner

Beeg
Beegie_B is offline   Reply With Quote
Old Nov 22nd, 2004, 12:20 PM   #4
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Ah, i guess that's what i get for full not reading the threads.....heh
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Nov 22nd, 2004, 3:17 PM   #5
Beegie_B
Programmer
 
Join Date: Nov 2004
Location: Windsor, Ontario, Canada
Posts: 32
Rep Power: 0 Beegie_B is on a distinguished road
Send a message via ICQ to Beegie_B Send a message via MSN to Beegie_B
hehe, it happens to the best of us

Beeg
Beegie_B is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:31 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC