Ewon TechForum
Providing technical solutions to technical requests


Create your own IP scanner
simon Offline
eWON Support
#1
Hi Guys,

This is an example of IP scanner in BASIC.
The idea is to know which device is connected to the LAN of your Flexy, especially when the Flexy is acting as a DHCP server on its LAN (See https://ewon.biz/sites/default/files/kb-...on_lan.pdf).

Here the SCAN is performed every minute.

You'll find also attached a webpage that displays the status of the scan (which devices are connected or disconnected).  This page must be copied in the usr/ directory of your eWON.
.zip   scan.zip (Size: 190 bytes / Downloads: 22)

PS : The script can be pasted as it is in the init section.

Code:
//Read DHCP Server parameters
ONDATE 1,"* * * * *","GOTO ScanIP"

ScanIpInit:
SETSYS COM, "LOAD"
DHCPSrvSTARTIP$ = GETSYS COM, "LANDHCPSStartIP"
DHCPSrvENDIP$ = GETSYS COM, "LANDHCPSEndIP"

//Compute the IP address range to test (I consider a mask of 255.255.255.0)
NetWorkAddr$ = @SplitString$(DHCPSrvSTARTIP$,1,".") + "." + @SplitString$(DHCPSrvSTARTIP$,2,".") + "." + @SplitString$(DHCPSrvSTARTIP$,3,".") + "."
FirstDigit% = VAL @SplitString$(DHCPSrvSTARTIP$,4,".")
LastDigit% = VAL @SplitString$(DHCPSrvENDIP$,4,".")
CurrentDigit% = FirstDigit%
ScanIsRunning% = 0
SCANSTATUS$ = "Scan is stopped"

ScanIP:
PRINT "IP SCAN START"
IF ScanIsRunning% = 1 THEN
  PRINT "Scan is already running"
  GOTO DontScan
ENDIF
ScanIsRunning% = 1
SCANSTATUS$ = "Scan is running"
CurrentDigit% = FirstDigit%
RESULT$ = ""

ScanNextIp:
  CLOSE 1
  ONSTATUS "goto ProcessStatus"
  Ip$ = NetWorkAddr$ +STR$ CurrentDigit%
  //We test the TCP port 80
  OPEN "tcp:"+Ip$+ ":80,10" FOR BINARY OUTPUT AS 1
  a% = GETSYS PRG,"ACTIONID"
DontScan:
END

ProcessStatus:
  b% = GETSYS PRG,"EVTINFO"
  IF b%=a% THEN
    SETSYS PRG,"ACTIONID",a%
    c% = GETSYS PRG,"ACTIONSTAT"
    IF c% = 0 THEN
      RESULT$ = RESULT$ + Ip$ + " is connected</br>"
      PRINT "PING "+Ip$+" success"
    ELSE
      RESULT$ = RESULT$ + Ip$ + " is disconnected</br>"
      PRINT "PING "+Ip$+" failed"
    ENDIF
    CurrentDigit% = CurrentDigit% + 1
    IF CurrentDigit% <= LastDigit% THEN
      GOTO ScanNextIp
    ELSE
      ScanIsRunning% = 0
      SCANSTATUS$ = "Scan is stopped"
      PRINT "IP SCAN END"
  ENDIF
END

Function SplitString$ ($StringToParse$,$Pos%, $char$)

$e% = 1
$loopnbr% = 0
$NextLine:
 $f% = INSTR $e% , $StringToParse$ , $char$
 //LAST ELEMENT
 IF $f% = 0 THEN  
    $B$ = $StringToParse$( $e% TO LEN $StringToParse$)
    GOTO $EndOfLine        
 ENDIF
 $loopnbr% = $loopnbr% + 1
 $B$ = $StringToParse$( $e% TO $f%-1)
 IF $Pos% = $loopnbr% THEN GOTO $EndOfLine
 $e% = $f% + 1 //REM Init for next loop/line            
 GOTO $NextLine
$EndOfLine:
$SplitString$ = $B$
EndFn

END
Reply



Possibly Related Threads…
  Create Directory Started by schlottke
2 Replies - 319 Views
04-04-2020, 01:00 AM
Last Post: schlottke
02-12-2019, 11:25 PM
Last Post: simon
07-11-2018, 11:42 PM
Last Post: simon
13-06-2018, 05:56 PM
Last Post: Prabu1984
  Create the first Tag in BASIC Started by simon
2 Replies - 2.645 Views
07-03-2018, 06:14 PM
Last Post: simon
15-06-2017, 10:05 AM
Last Post: simon
08-06-2017, 02:40 PM
Last Post: Ludo



Users browsing this thread:
1 Guest(s)



Theme © Ewon 2019 - Forum software by © MyBB - Cookie policy