Что нового

[Сеть, интернет] Сканер сети по диапазону ip

Renz

Осваивающий
Сообщения
63
Репутация
36
AutoIt: v3.3.6.1

Версия: 0.1

Категория: Сеть

Описание: Небольшой сканер сети по диапазону IP адресов.
Cканирует порты на доступность и отображает ресурсы.
Результат отображается в виде дерева.
Работает в диапазоне : ххх.ххх.0.0-ххх.ххх.255.255

Код:
Код:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <iNet.au3>
#include <NetShare.au3>
#Include <GuiTreeView.au3>
;#Region ### START Koda GUI section ### Form=c:\koda_1.7.3.0\forms\scaner.kxf
$Form1_1 = GUICreate("Scaner Lan", 310, 323, 195, 125)
$IPAddress1 = _GUICtrlIpAddress_Create($Form1_1, 16, 32, 130, 21)
_GUICtrlIpAddress_Set($IPAddress1, "0.0.0.0")
$IPAddress2 = _GUICtrlIpAddress_Create($Form1_1, 168, 32, 130, 21)
_GUICtrlIpAddress_Set($IPAddress2, "0.0.0.0")
$Checkbox1 = GUICtrlCreateCheckbox("FTP-21", 16, 64, 73, 17) ;f
$Checkbox2 = GUICtrlCreateCheckbox("80-Port", 16, 80, 73, 17) ;o
$Checkbox3 = GUICtrlCreateCheckbox("Resources", 96, 80, 73, 17) ;s
$Button1 = GUICtrlCreateButton("Scan", 8, 272, 75, 25)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1_1)
$Button2 = GUICtrlCreateButton("Stop", 88, 272, 75, 25)
$Checkbox4 = GUICtrlCreateCheckbox("RDP-3389", 176, 64, 97, 17) ;r
$Label1 = GUICtrlCreateLabel("Scaner Lan v0.1", 8, 8, 83, 17)
$Label2 = GUICtrlCreateLabel("Renz", 256, 8, 38, 17)
$Checkbox5 = GUICtrlCreateCheckbox("Telnet-23", 96, 64, 73, 17) ;t
$Button3 = GUICtrlCreateButton("Clean", 224, 272, 75, 25)
$Input1 = GUICtrlCreateInput("1433", 200, 80, 41, 21)
$Label3 = GUICtrlCreateLabel("TCP-port", 248, 80, 46, 17)
$Checkbox6 = GUICtrlCreateCheckbox("", 176, 80, 17, 17) ;p
$Label4 = GUICtrlCreateLabel("_", 152, 32, 10, 17, $SS_CENTER)
$TreeView1 = GUICtrlCreateTreeView(8, 104, 289, 161)
GUISetState(@SW_SHOW)
;#EndRegion ### END Koda GUI section ###
Local Const $sShareName = "AutoIt Share"
$Share=0
TCPStartup ()
If _Net_Share_ShareCheck (@ComputerName, $sShareName) = -1 Then
	; Create a share on the local computer
	_Net_Share_ShareAdd (@ComputerName, $sShareName, 0, "C:\", "AutoIt Share Comment")
	If @error Then 
		MsgBox (4096, "Information", "Share add error : " & @error)
	Else
		$Share=1
	EndIf
EndIf
			
While 1
	$nMsg = GUIGetMsg()
	Select
		Case $nMsg = $GUI_EVENT_CLOSE
			Exit
		Case $nMsg = $Button1
			$sPort = GUICtrlRead($Input1)
			$state =''
			$state = Stat()
			;MsgBox(1,"",$state)
			$aIp1 = _GUICtrlIpAddress_GetArray($IPAddress1)
			$aIp2 = _GUICtrlIpAddress_GetArray($IPAddress2)
		
			While $aIp1[2] <= $aIp2[2]
				While 1 
					$nMsg = GUIGetMsg()
					If $nMsg = $Button2 Then ExitLoop 2
					If $aIp1[3] > 255 Then
						$aIp1[3]=0
						ExitLoop
					EndIf
					If $aIp1[2] = $aIp2[2] And $aIp1[3] > $aIp2[3]  Then
						ExitLoop 2
					EndIf
					$sIp = $aIp1[0]&'.'& $aIp1[1]&'.'& $aIp1[2]&'.'& $aIp1[3]
					If Ping($sIp ,250) <> 0 Then
						$TreeViewItem = GUICtrlCreateTreeViewItem ( $sIp, $TreeView1 )
						If StringInStr($state,'f') Or StringInStr($state,'o') Or StringInStr($state,'r') Or StringInStr($state,'t') Or StringInStr($state,'p')Then
							Opt("TCPTimeout",25)
							$rez = ScanPort($sIp,$state,$sPort)
							Opt("TCPTimeout",100)
							If $rez <> '' Then
								AddToTree($TreeViewItem,$rez,$sPort)
							EndIf
						EndIf
						If StringInStr($state,'s') Then
							;If $Share = 1 Then
								$sName = _TCPIpToName($sIp)
								ConsoleWrite ( $sName& @CRLF)
								$aInfo = _Net_Share_ShareEnum ($sName)
								If $aInfo[0][0] > 0 Then
									$TreeViewItemRes = GUICtrlCreateTreeViewItem ( "Resources", $TreeViewItem )
									For $iI = 1 To $aInfo[0][0]
										$TreeViewItemResName = GUICtrlCreateTreeViewItem ($aInfo[$iI][0],$TreeViewItemRes)
										$TreeViewItemResName1 = GUICtrlCreateTreeViewItem ("Share type- "&_Net_Share_ResourceStr ($aInfo[$iI][1]),$TreeViewItemResName)
										$TreeViewItemResName1 = GUICtrlCreateTreeViewItem ("Local path- " & $aInfo[$iI][6],$TreeViewItemResName)
									Next
								EndIf
							;EndIf	
							
						EndIf
						GUISetState(@SW_SHOW)
						;ConsoleWrite ( $sIp& @CRLF)
					EndIf
					$aIp1[3]+=1	
				WEnd
				$aIp1[2]+=1	
			WEnd
		Case $nMsg = $Button3	
			_GUICtrlTreeView_DeleteAll($TreeView1)
	EndSelect
WEnd
; Delete the share
_Net_Share_ShareDel (@ComputerName, $sShareName)
If @error Then MsgBox (4096, "Information", "Share delete error : " & @error)
Func Stat()
	$state =''
	if GUICtrlRead($Checkbox1) = 1 Then
		$state = $state&'f'
	EndIf
	if GUICtrlRead($Checkbox2) = 1 Then
		$state = $state&'o'
	EndIf
	if GUICtrlRead($Checkbox3) = 1 Then
		$state = $state&'s'
	EndIf
	if GUICtrlRead($Checkbox4) = 1 Then
		$state = $state&'r'
	EndIf
	if GUICtrlRead($Checkbox5) = 1 Then
		$state = $state&'t'
	EndIf
	if GUICtrlRead($Checkbox6) = 1 Then
		$state = $state&'p'
	EndIf
	Return $state
EndFunc


Func ScanPort($sIp,$sta,$port)
	$rez = ''
	If StringInStr($sta,'f') Then
		If TCPConnect ( $sIp, 21 ) <> -1 Then
			$rez = $rez & 'f'
		EndIf
	EndIf
	If StringInStr($sta,'o') Then
		If TCPConnect ( $sIp, 80 ) <> -1 Then
			$rez = $rez & 'o'
		EndIf
	EndIf
	If StringInStr($sta,'r') Then
		If TCPConnect ( $sIp, 3389 ) <> -1 Then
			$rez = $rez & 'r'
		EndIf
	EndIf
	If StringInStr($sta,'t') Then
		If TCPConnect ( $sIp, 23 ) <> -1 Then
			$rez = $rez & 't'
		EndIf
	EndIf
	If StringInStr($sta,'p') Then
		If TCPConnect ( $sIp, $port ) <> -1 Then
			$rez = $rez & 'p'
		EndIf
	EndIf
	Return $rez
EndFunc

Func AddToTree($TreeViewItem,$rez,$sPort)
	If StringInStr($rez,'f') Then
		GUICtrlCreateTreeViewItem ( "ftp-21", $TreeViewItem )
	EndIf
	If StringInStr($rez,'o') Then
		GUICtrlCreateTreeViewItem ( "80-Port", $TreeViewItem )
	EndIf
	If StringInStr($rez,'r') Then
		GUICtrlCreateTreeViewItem ( "RDP-3389", $TreeViewItem )
	EndIf
	If StringInStr($rez,'t') Then
		GUICtrlCreateTreeViewItem ( "Telnet-23", $TreeViewItem )
	EndIf
	If StringInStr($rez,'p') Then
		GUICtrlCreateTreeViewItem ( $sPort&"-port", $TreeViewItem )
	EndIf
EndFunc

Файл: EXE

Снимок:


Источник: http://autoit-script.ru
Автор(ы): Renz
 

Garrett

Модератор
Локальный модератор
Сообщения
3,999
Репутация
964
Renz [?]
Ну так, и оформите EXE в первый пост, зачем его отдельно выкладывать.


Добавлено:
Сообщение автоматически объединено:

А это вам бонус (намёк) ;)
 

Ganibal95

GreenBytes
Сообщения
877
Репутация
240
Renz
Когда начал сканировать надо чтоб кнопка: 'Scan' была недоступна... :smile:
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
Renz,
Эти библиотеки лишние:
Код:
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
 
Верх