Calculadora de Redes IP

y programas personales para otros como tu, puede que te corrijan ;)
Responder
Avatar de Usuario
frp64
Mensajes: 18
Registrado: 20 Jul 2010, 09:40
Ubicación: Canarias

Calculadora de Redes IP

Mensaje por frp64 »

Buenas,

Aquí va una calculadora de redes IP, falta aún implementar alguno de los apartados:

Código: Seleccionar todo


#include <GUIConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <String.au3>

dim $suma, $mas1, $mas2, $mas3, $mas4
dim $dir1, $dir2, $dir3, $dir4
dim $dred1, $dred2, $dred3, $dred4
dim $bred1, $bred2, $bred3, $bred4
dim $rred11, $rred12, $rred13, $rred14
dim $rred21, $rred22, $rred23, $rred24
dim $nhost, $nsubnet

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Calculadora de Redes IP", 570, 450, 210, 131)
$Input1 = GUICtrlCreateInput("", 16, 32, 65, 21)
$Input2 = GUICtrlCreateInput("", 96, 32, 65, 21)
$Input3 = GUICtrlCreateInput("", 173, 31, 65, 21)
$Input4 = GUICtrlCreateInput("", 256, 32, 65, 21)
$Combo1 = GUICtrlCreateCombo("255", 16, 88, 65, 25)
GUICtrlSetData ($Combo1, "255|254|252|248|240|224|192|128|0")
$Combo2 = GUICtrlCreateCombo("255", 96, 88, 65, 25)
GUICtrlSetData ($Combo2, "255|254|252|248|240|224|192|128|0")
$Combo3 = GUICtrlCreateCombo("255", 176, 88, 65, 25)
GUICtrlSetData ($Combo3, "255|254|252|248|240|224|192|128|0")
$Combo4 = GUICtrlCreateCombo("0", 256, 88, 65, 25)
GUICtrlSetData ($Combo4, "255|254|252|248|240|224|192|128|0")
$Button1 = GUICtrlCreateButton("Cálculo de Direcciones", 16, 128, 150, 25, 0)
$Button2 = GUICtrlCreateButton("Nueva Entrada", 210, 128, 150, 25, 0)
GUICtrlSetState (-1, $GUI_DISABLE)
$Salir = GUICtrlCreateButton("Salir", 405, 128, 150, 25, 0)
$Input5 = GUICtrlCreateInput("", 344, 32, 210, 21, $ES_READONLY) ;Binario dirección IP
$Input6 = GUICtrlCreateInput("", 344, 88, 210, 21, $ES_READONLY) ;Binario máscara IP
$Input7 = GUICtrlCreateInput("", 16, 184, 65, 21, $ES_READONLY) 
$Input8 = GUICtrlCreateInput("", 96, 184, 65, 21, $ES_READONLY)
$Input9 = GUICtrlCreateInput("", 176, 184, 65, 21, $ES_READONLY)
$Input10 = GUICtrlCreateInput("", 256, 184, 65, 21, $ES_READONLY)
$Input11 = GUICtrlCreateInput("", 344, 184, 210, 21, $ES_READONLY) ;Binario dirección de red
$Input12 = GUICtrlCreateInput("", 16, 232, 65, 21, $ES_READONLY)
$Input13 = GUICtrlCreateInput("", 96, 232, 65, 21, $ES_READONLY)
$Input14 = GUICtrlCreateInput("", 176, 232, 65, 21, $ES_READONLY)
$Input15 = GUICtrlCreateInput("", 256, 232, 65, 21, $ES_READONLY)
$Input16 = GUICtrlCreateInput("", 344, 232, 210, 21, $ES_READONLY) ;Binario dirección de broadcast
$Input17 = GUICtrlCreateInput("", 16, 296, 65, 21, $ES_READONLY)
$Input18 = GUICtrlCreateInput("", 96, 296, 65, 21, $ES_READONLY)
$Input19 = GUICtrlCreateInput("", 176, 296, 65, 21, $ES_READONLY)
$Input20 = GUICtrlCreateInput("", 256, 296, 65, 21, $ES_READONLY)
$Input21 = GUICtrlCreateInput("", 344, 296, 210, 21, $ES_READONLY)
$Input22 = GUICtrlCreateInput("", 16, 344, 65, 21, $ES_READONLY)
$Input23 = GUICtrlCreateInput("", 96, 344, 65, 21, $ES_READONLY)
$Input24 = GUICtrlCreateInput("", 176, 344, 65, 21, $ES_READONLY)
$Input25 = GUICtrlCreateInput("", 256, 344, 65, 21, $ES_READONLY)
$Input26 = GUICtrlCreateInput("", 344, 344, 210, 21, $ES_READONLY)
$Combo5 = GUICtrlCreateCombo("", 16, 400, 145, 25)
GUICtrlSetState ($Combo5, $GUI_DISABLE)
$Combo6 = GUICtrlCreateCombo("", 176, 400, 145, 25)
GUICtrlSetState ($Combo6, $GUI_DISABLE)
$Input27 = GUICtrlCreateInput("", 345, 400, 85, 21, $ES_READONLY)
$Input28 = GUICtrlCreateInput("", 470, 400, 85, 21, $ES_READONLY)
$Label1 = GUICtrlCreateLabel("Introduce una dirección IP válida", 16, 8, 160, 17)
$Label2 = GUICtrlCreateLabel("Máscara de Subred", 16, 64, 97, 17)
$Label3 = GUICtrlCreateLabel("Representación binaria", 400, 8, 113, 17)
$label4 = GUICtrlCreateLabel("Dirección de Red", 16, 160, 87, 17)
$Label5 = GUICtrlCreateLabel("Dirección de Broadcast", 16, 208, 115, 17)
$Label6 = GUICtrlCreateLabel("Direcciones de Equipos:", 16, 256, 119, 17)
$Label7 = GUICtrlCreateLabel("Desde", 16, 274, 35, 17)
$Label8 = GUICtrlCreateLabel("Hasta", 16, 320, 32, 17)
$Label9 = GUICtrlCreateLabel("Rango de Redes", 16, 378, 85, 17)
$Label10 = GUICtrlCreateLabel("Rango de Hosts", 176, 378, 81, 17)
$Label11 = GUICtrlCreateLabel("Nº Redes:", 345, 378, 53, 17)
$Label12 = GUICtrlCreateLabel("Nº Hosts:", 470, 378, 49, 17)
GUISetState(@SW_SHOW)

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Salir
			Exit
		Case $Button1
			_lee()
			_depura_dir()
			$bidir1 = _binario($dir1)
			$bidir2 = _binario($dir2)
			$bidir3 = _binario($dir3)
			$bidir4 = _binario($dir4)
			$binario1 = $bidir1 & "." & $bidir2 & "." & $bidir3 & "." & $bidir4
			GUICtrlSetData ($Input5, $binario1)
			$bimas1 = _binario($mas1)
			$bimas2 = _binario($mas2)
			$bimas3 = _binario($mas3)
			$bimas4 = _binario($mas4)
			$binario2 = $bimas1 & "." & $bimas2 & "." & $bimas3 & "." & $bimas4
			GUICtrlSetData ($Input6, $binario2)
			$dred1 = _escribe_dred($bidir1, $bimas1)
			$dred2 = _escribe_dred($bidir2, $bimas2)
			$dred3 = _escribe_dred($bidir3, $bimas3)
			$dred4 = _escribe_dred($bidir4, $bimas4)
			GUICtrlSetData ($Input7, $dred1)
			GUICtrlSetData ($Input8, $dred2)
			GUICtrlSetData ($Input9, $dred3)
			GUICtrlSetData ($Input10, $dred4)
			$bidred1 = _binario($dred1)
			$bidred2 = _binario($dred2)
			$bidred3 = _binario($dred3)
			$bidred4 = _binario($dred4)
			$binario3 = $bidred1 & "." & $bidred2 & "." & $bidred3 & "." & $bidred4
			GUICtrlSetData ($Input11, $binario3)
			_broadcast()
			GUICtrlSetData ($Input12, $bred1)
			GUICtrlSetData ($Input13, $bred2)
			GUICtrlSetData ($Input14, $bred3)
			GUICtrlSetData ($Input15, $bred4)
			$bibred1 = _binario($bred1)
			$bibred2 = _binario($bred2)
			$bibred3 = _binario($bred3)
			$bibred4 = _binario($bred4)
			$binario4 = $bibred1 & "." & $bibred2 & "."  & $bibred3 & "." & $bibred4
			GUICtrlSetData ($Input16, $binario4)
			_rred1()
			_rred2()
			GUICtrlSetData ($Input17, $rred11)
			GUICtrlSetData ($Input18, $rred12)
			GUICtrlSetData ($Input19, $rred13)
			GUICtrlSetData ($Input20, $rred14)
			$brred11 = _binario($rred11)
			$brred12 = _binario($rred12)
			$brred13 = _binario($rred13)
			$brred14 = _binario($rred14)
			$binario5 = $brred11 & "." & $brred12 & "."  & $brred13 & "." & $brred14
			GUICtrlSetData ($Input21, $binario5)
			GUICtrlSetData ($Input22, $rred21)
			GUICtrlSetData ($Input23, $rred22)
			GUICtrlSetData ($Input24, $rred23)
			GUICtrlSetData ($Input25, $rred24)
			$brred21 = _binario($rred21)
			$brred22 = _binario($rred22)
			$brred23 = _binario($rred23)
			$brred24 = _binario($rred24)
			$binario6 = $brred21 & "." & $brred22 & "."  & $brred23 & "." & $brred24
			GUICtrlSetData ($Input26, $binario6)
			_leebits($bimas4)
			GUICtrlSetData ($Input27, $nsubnet)
			GUICtrlSetData ($Input28, $nhost)
			
   EndSwitch
WEnd

Func _lee()
   $dir1 = GUICtrlRead ($Input1)
   $dir2 = GUICtrlRead ($Input2)
   $dir3 = GUICtrlRead ($Input3)
   $dir4 = GUICtrlRead ($Input4)
   $mas1 = GUICtrlRead ($Combo1)	
   $mas2 = GUICtrlRead ($Combo2)
   $mas3 = GUICtrlRead ($Combo3)
   $mas4 = GUICtrlRead ($Combo4)
EndFunc

Func _leebits($x)
   $uno = 0
   $cero = 0
   $dec1 = 1
   
   For $i = 1 To 8
	  If StringMid ($x, $i, 1) = "0" Then
		 $cero = $cero + 1
	  Else
		 $uno = $uno + 1
	  EndIf
   Next
   for $j = 1 To $cero
	  $dec1 = $dec1 * 2
   Next
   $nhost = $dec1 - 2
   $dec2 = 1
   for $j = 1 To $uno
	  $dec2 = $dec2 * 2
   Next
   $nsubnet = $dec2
EndFunc

Func _escribe_dred($x1, $x2)
$sbin = ""
$decimal = 0
$dec = 1

For $i = 1 to 8
   $r1 = Number(StringMid($x1, $i, 1))
   $r2 = Number(StringMid($x2, $i, 1))
   If ($r1 AND $r2) = True Then
	  $c = "1"
   Else
	  $c = "0"
   EndIf
   $sbin = $sbin & $c
Next
For $i = 1 To StringLen($sbin)
   If StringMid ($sbin, $i, 1) = "1" Then
	  $pot = 8 - $i
	  for $j = 1 To $pot
		 $dec = $dec * 2
	  Next
   Else
	  ContinueLoop
   EndIf
   $decimal = $decimal + $dec
   $dec = 1
Next
Return $decimal

EndFunc

Func _depura_dir()

If $dir1 > 255 or $dir1 < 0 Then
   MsgBox (0, "Calculadora de Redes IP", "Escriba un número entre 0 y 255")
   GUICtrlSetData ($Input1, "")
   GUICtrlSetState ($Input1, $GUI_FOCUS)
Endif
If $dir2 > 255 or $dir2 < 0 Then
	MsgBox (0, "Calculadora de Redes IP", "Escriba un número entre 0 y 255")
	GUICtrlSetData ($Input2, "")
	GUICtrlSetState ($Input2, $GUI_FOCUS)
Endif
If $dir3 > 255 or $dir3 < 0 Then
	MsgBox (0, "Calculadora de Redes IP", "Escriba un número entre 0 y 255")
	GUICtrlSetData ($Input3, "")
	GUICtrlSetState ($Input3, $GUI_FOCUS)
Endif
If $dir4 > 255 or $dir4 < 0 Then
	MsgBox (0, "Calculadora de Redes IP", "Escriba un número entre 0 y 255")
	GUICtrlSetData ($Input4, "")
	GUICtrlSetState ($Input4, $GUI_FOCUS)
Endif
if $mas1 <> 255 Then
   GUICtrlSetData ($Combo2, "0")
   GUICtrlSetData ($Combo3, "0")
   GUICtrlSetData ($Combo4, "0")
EndIf
if $mas1 = 255 and $mas2 <> 255 Then
	GUICtrlSetData ($Combo3, "0")
	GUICtrlSetData ($Combo4, "0")
EndIf
If $mas1 = 255 and $mas2 = 255 and $mas3 <> 255 Then
	GUICtrlSetData ($Combo4, "0")
EndIf
EndFunc 
 
Func _binario($var)
Local $x = ""
Local $res
Local $cero

While $var >= 1
   if $var = 1 then
	  $x = $x & $var
	  ExitLoop
   Endif
   if Mod($var, 2) = 0 Then
	  $res = String(0)
	  $x = $x & $res
	  $var = $var / 2
	  ContinueLoop
   EndIf
   if Mod($var, 2) = 1 Then
	  $res = String(1)
	  $x = $x & $res
	  $var = ($var - 1) / 2
	  ContinueLoop
   EndIf
WEnd
If StringLen ($x) < 8 Then
   $cero = 8 - StringLen ($x)
   For $i = 1 To $cero
	  $x = $x & "0"
   Next
EndIf

$binary = _StringReverse($x)
Return $binary

EndFunc

Func _broadcast()
   $bred1 = $dred1 + 255 - $mas1
   $bred2 = $dred2 + 255 - $mas2
   $bred3 = $dred3 + 255 - $mas3
   $bred4 = $dred4 + 255 - $mas4
EndFunc
Func _rred1()
   $rred11 = $dred1
   $rred12 = $dred2
   $rred13 = $dred3
   $rred14 = $dred4 + 1
EndFunc

Func _rred2()
   $rred21 = $bred1
   $rred22 = $bred2
   $rred23 = $bred3
   $rred24 = $bred4 - 1
EndFunc
Saludos
Avatar de Usuario
Dany
Profesional del Autoit
Mensajes: 651
Registrado: 28 Mar 2012, 22:49

Re: Calculadora de Redes IP

Mensaje por Dany »

Excelente muy buena la Herramienta :smt023


No uses dim usa Global.

saludos
  • ............................................Imagen
    ......................................Imagen
Responder