J'ai fait une petite calculette IP pour le C-128. Il suffit d'introduire l'adresse IP et le masque, il calcule le reste.
Code : Tout sélectionner
calculette ip
-------------
ip adresse (192.168.1.0)=? 192.168.1.5
masque (255.255.240.0)=? 255.255.255.0
masque id=/ 24
masque inverse (pour switch)=00000000.00000000.00000000.11111111 (0.0.0.255)
adresse reseau=11000000.10101000.00000001.00000000 (192.168.1.0)
adresse broadcast=11000000.10101000.00000001.11111111 (192.168.1.255)
adresses totales= 256
adresses disponibles= 254
ready.
Code : Tout sélectionner
10 REM CALCULETTE IP.
20 REM IP$=ADRESSE IP DU PC
30 REM MA$=MASQUE DU RESEAU
40 REM IB$=ADRESSE IP EN BINAIRE (SANS LES POINTS)
50 REM MB$=MASQUE EN BINAIRE (SANS LES POINTS)
60 FAST:SCNCLR:COLOR 5,8
70 PRINT "CALCULETTE IP"
80 PRINT "-------------"
90 INPUT "IP ADRESSE (192.168.1.0)=";IP$
100 W$=IP$+".":GOSUB 1010:IB$=WF$
110 IF WF$="NULL" THEN PRINT "ADRESSE IP N'EST PAS CORRECTE": GOTO 90
120 INPUT "MASQUE (255.255.240.0)=";MA$
130 W$=MA$+".":GOSUB 1010:GOSUB 1370:MB$=WF$
140 IF WF$="NULL" THEN PRINT "MASQUE IP N'EST PAS CORRECTE": GOTO 120
150 AR$="":AB$="":ID=0:MI$=""
160 FOR I=1 TO 32
170 CI$=MID$(IB$,I,1):CM$=MID$(MB$,I,1)
180 IF CM$="1" THEN ID=ID+1:CA$="0":MI$=MI$+CA$:ELSE CA$="1":MI$=MI$+CA$
190 AR$=AR$+RIGHT$(STR$(VAL(CI$) AND VAL(CM$)),1)
200 AB$=AB$+RIGHT$(STR$(VAL(CI$) OR VAL(CA$)),1)
210 IF I=8 OR I=16 OR I=24 THEN MI$=MI$+".":AR$=AR$+".":AB$=AB$+"."
220 NEXT I
230 PRINT "masque id=/";id
240 print "masque inverse (pour switch)=";mi$;:w$=mi$:gosub 1450:print ".(
";wf$;")"
250 print "adresse reseau=";ar$;:w$=ar$:gosub 1450:print ".(";wf$;")"
260 print "adresse broadcast=";ab$;:w$=ab$:gosub 1450:print ".(";wf$;")"
270 at=32-id
280 print "adresses totales=";2^at
290 print "adresses disponibles=";2^at-2
300 end
1000 rem **** validation & conversion ip ****
1010 gosub 1220
1020 if wf$="null" then return
1030 wf$="":wb$=""
1040 for wi=1 to len(w$)
1050 wc$=mid$(w$,wi,1)
1060 if wc$="." then gosub1110:wf$=wf$+wt$:wb$="":goto 1080
1070 wb$=wb$+wc$
1080 next wi
1090 return
1100 rem **** conversion en binaire ****
1110 wb=val(wb$):wt$=""
1120 wc=int(wb/2)
1130 wa=wb-wc*2
1140 wt$=right$(str$(wa),1)+wt$
1150 if wc>0 then wb=wc:goto 1120
1160 if len(wt$)=8 then 1200
1170 for wo=1 to 8-len(wt$)
1180 wt$="0"+wt$
1190 next wo
1200 return
1210 rem **** validation de l'adresse ip ****
1220 if len(w$)>16 then wf$="null":goto 1320
1230 wa=1:wi=1:wf$="":wb$=""
1240 do while (wi<len(w$) and wf$<>"null")
1250 wc$=mid$(w$,wi,1)
1260 if wc$="." then wa=wa+1:gosub 1330:wb$="":goto 1290
1270 if wc$<"0" or wc$>"9" then wf$="null"
1280 wb$=wb$+wc$
1290 wi=wi+1
1300 loop
1310 if wa<>4 then wf$="null"
1320 return
1330 if wb$="" then wf$="null"
1340 if val(wb$)>255 then wf$="null"
1350 return
1360 rem **** validation specifique du masque ****
1370 wa=0
1380 for wi=1 to 35
1390 wc$=mid$(wf$,wi,1)
1400 if wc$="0" then wa=1
1410 if wc$="1" and wa=1 then wf$="null"
1420 next wi
1430 return
1440 rem **** convertion binaire -> decimale ****
1450 wf$=""
1460 wb$=left$(w$,8):gosub 1510:wf$=wf$+wc$+"."
1470 wb$=mid$(w$,10,8):gosub 1510:wf$=wf$+wc$+"."
1480 wb$=mid$(w$,19,8):gosub 1510:wf$=wf$+wc$+"."
1490 wb$=mid$(w$,28,8):gosub 1510:wf$=wf$+wc$
1500 return
1510 wc=0
1520 for wi=8 to 1 step -1
1530 wc=wc+val(mid$(wb$,wi,1))*2^(8-wi)
1540 next wi
1550 wc$=right$(str$(wc),len(str$(wc))-1)
1560 return