Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Who's on my network.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Who's on my network.

    Code:
    '   Who's on my network
    '
    '   With a popularity of (uggg) wireless networks, it is sometimes possible for someone else
    '   with a wireless adaptor to accidently or on purpose get into your own home network.
    '
    '   If you suspect a hack, run this program and it should alert you that someone is there.
    '   Now what you can do about it....Well, your guess is probably better than mine.
    '
    '   One issue I haven't been able to resolve.
    '
    '   If you have static IP addressing, there shouldn't be a problem but you may run across a
    '   problem if you have dynamic IP addressing since they can change from time to time.
    '
    '   Written in CC4.04, I have "borrowed" several routines from the forums to hodge-podge this
    '   program together. I tried to give credit where credit is due but I probably forgot somebody.
    '   Apologies.
    '
    '   I key'd the detection routine to the MAC address instead of DeviceNames$ since the latter
    '   sometimes returns a nul string and it's also faster. Mac addresses, on the other hand, are
    '   always there.
    '
    '   Note: If a device (printer, network PC or other device is off, nothing will be returned
    '         for that device.
    '
    '   Of course, questions/comments are always welcome. Please post them in the CC forum.
    
    DECLARE FUNCTION SendARP LIB "iphlpapi.dll" ALIAS "SendARP" _
            (BYVAL DestIP AS DWORD, BYVAL SrcIP AS DWORD, pMacAddr AS DWORD, _
            PhyAddrLen AS DWORD) AS DWORD
    '
    DECLARE FUNCTION inet_addr LIB "wsock32.dll" ALIAS "inet_addr" (cp AS ASCIIZ) AS DWORD
    
    DECLARE FUNCTION GetMACaddress(ASCIIZ) AS STRING        '
                                                            '
        %no_error = 0                                       '
                                                            '
        FUNCTION PBMAIN()                                   '
        LOCAL ipLong   AS LONG                              '
        LOCAL w,x,y,z  AS LONG                              '
        LOCAL flag     AS LONG                              '
        LOCAL StringIP AS STRING                            '
        LOCAL sMac     AS STRING                            '
        LOCAL tm       AS ASCIIZ * 16                       '
                                                            '
        fi$ = "SafeList.txt"                                '
        OPEN fi$ FOR BINARY AS #1                           ' Just to make sure the file
        CLOSE #1                                            ' exists
                                                            '
        f$ = "###"                                          '
        f1$ = "###,###,###,###"                             '
        COLOR 14,1                                          '
        CLS                                                 '
                                                            '
        FOR w = 192 TO 192                                  '
        FOR x = 168 TO 168                                  '
        FOR y =   1 TO   1                                  '
        FOR z = 100 TO 125                                  '<--Starting address of my home network
                                                            '
    REM *******************************                     '
    REM * Build the string IP address *                     '
    REM *******************************                     '
                                                            '
        StringIP =            USING$(f$,w) + "."            '
        StringIP = StringIP + USING$(f$,x) + "."            '
        StringIP = StringIP + USING$(f$,y) + "."            '
        StringIP = StringIP + USING$(f$,z)                  '
        StringIP = REMOVE$(StringIP," ")                    '
                                                            '
    REM ********************************************************************
    REM * Convert StringIP to a long integer                               *
    REM * Eros Olmi                                                        *
    REM * http://www.powerbasic.com/support/pbforums/showthread.php?t=38093*
    REM ********************************************************************
                                                            '
        IpLong = ((VAL(PARSE$(StringIP, ".", 4))  * _       '
             256 + VAL(PARSE$(StringIP, ".", 3))) * _       '
             256 + VAL(PARSE$(StringIP, ".", 2))) * _       '
             256 + VAL(PARSE$(StringIP, ".", 1))            '
                                                            '
    REM *********************************************************************
    REM * Get the MAC address of the attached device                        *
    REM * John McWilliams                                                   *
    REM * http://www.powerbasic.com/support/pbforums/showthread.php?t=24169 *
    REM *********************************************************************
                                                            '
        tm = StringIP                                       '
        sMAC = GetMACaddress(tm)                            '<== What's the MAC address
                                                            '    of this device?
    REM *********************************************       '
    REM * It's a lot faster getting the device name *       '
    REM * after making sure there's a Mac Address   *       '
    REM * attached it it.                           *       '
    REM *********************************************       '
                                                            '
        IF sMac <> "" THEN                                  '<:
        HOST NAME (ipLong) TO DeviceName$                   ' |
        END IF                                              '<:
                                                            '
        IF DeviceName$ = "" THEN                            '<:
        DeviceName$ = "Unknown Device"                      ' |
        END IF                                              '<:
                                                            '
        PRINT;StringIP ; TAB(20) ; USING$(f1$,iplong) ; _   '
                         TAB(40);DeviceName$;TAB(60);sMac   '
        IF LEN(sMac) <> 17 THEN sMac = ""                   '
                                                            '
        IF sMac <> "" THEN                                  '<--:
        flag = 0                                            '   |
        OPEN fi$ FOR INPUT AS #1                            '   |
        DO UNTIL EOF(1)                                     '<: |
        INPUT #1,t1$ , t2$ , t3$                            ' | | String IP Address
        IF t3$ = sMac THEN flag = 1                         ' | |
        LOOP                                                '<: |
        CLOSE #1                                            '   |
                                                            '   |
    REM *******************************                     '   |
    REM * Match not found. Query user *                     '   |
    REM *******************************                     '   |
        IF flag = 0 THEN                                    '<-:|
        CLS                                                 '  ||
        LOCATE  5,30 : PRINT;StringIP                       '  ||
        LOCATE  7,30 : PRINT;DeviceName$                    '  ||
        LOCATE  9,30 : PRINT;sMac                           '  ||
        LOCATE 13,30 : PRINT;"not found. Accept? (Y/N)"     '  ||
        DO                                                  '<:||
        WHILE INSTAT = 0 : WEND                             ' |||
        an$ = UCASE$(INKEY$)                                ' |||
        IF an$ = "Y" OR an$ = "N" THEN EXIT LOOP            ' |||
        BEEP                                                ' |||
        LOOP                                                '<:||
                                                            '  ||
        IF an$ = "Y" THEN                                   '<:||
        OPEN fi$ FOR BINARY AS #1                           ' |||
        SEEK #1,LOF(1) + 1                                  ' |||
        PUT$ #1,StringIP + ","                              ' |||
        PUT$ #1,DeviceName$ + ","                           ' |||
        PUT$ #1,sMac + $CRLF                                ' |||
        CLOSE #1                                            ' |||
        END IF                                              '<:||
        END IF                                              '<-:|
        END IF                                              '<--:
                                                            '
                                                            '
        StringIP = ""                                       '
        IPlong = 0                                          '
        DeviceName$ = ""                                    '
        sMac = ""                                           '
                                                            '
        IF INKEY$ = CHR$(27) THEN EXIT FUNCTION             '
                                                            '
        NEXT : NEXT : NEXT : NEXT                           '
        BEEP                                                '
        WAITKEY$                                            '
        END FUNCTION                                        '
                                                            '
                                                            '
    FUNCTION GetMACaddress(szIP AS ASCIIZ) AS STRING        '
                                                            '
        'John McWilliams                                    '
        'http://www.powerbasic.com/support/pbforums/showthread.php?t=24169
        '
        '  Input: IP address from which you want the MAC address
        ' Output: The MAC address as "00-00-00-00-00-00" on success
        '         null string on failure. Bad IP addresses returns a
        '         null string.
        '
        'Depends: win32API.inc, iphlpapi.inc, wsock32.inc
        '
        LOCAL Result        AS LONG
        LOCAL MACbytes      AS LONG
        DIM   ipArray(0)    AS DWORD
        DIM   p             AS BYTE PTR
        '
        FUNCTION = "" : IF LEN(TRIM$(szIP)) = 0 THEN EXIT FUNCTION
        '
        'The first six bytes of the array receive the physical address that corresponds to the IP
        'address specified by szIP. See "SendARP" in MSDN for more info.
        MACbytes = 6  'MACbytes is NOT a statement about Apple Macintosh's
        '
        Result = SendARP(inet_addr(szIP), 0, ipArray(0), MACbytes)
        IF Result = %NO_ERROR THEN   'Success
           p = VARPTR(ipArray(0))
           FUNCTION = HEX$(@p, 2) & "-" & HEX$(@p[1], 2) & "-" & HEX$(@p[2], 2) & "-" & HEX$(@p[3], 2) & _
                      "-" & HEX$(@p[4], 2) & "-" & HEX$(@p[5], 2)
        END IF
    END FUNCTION
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

    #2
    Code:
    '   Who's on my network version 1.5
    '   Modified so you can specify your own TCP/IP ranges.
    '
    '   With a popularity of (uggg) wireless networks, it is sometimes possible for someone else
    '   with a wireless adaptor to accidently or on purpose get into your own home network.
    '
    '   If you suspect a hack, run this program and it should alert you that someone is there.
    '   Now what you can do about it....Well, your guess is probably better than mine.
    '
    '   One issue I haven't been able to resolve.
    '
    '   If you have static IP addressing, there shouldn't be a problem but you may run across a
    '   problem if you have dynamic IP addressing since they can change from time to time.
    '
    '   Written in CC4.04, I have "borrowed" several routines from the forums to hodge-podge this
    '   program together. I tried to give credit where credit is due but I probably forgot somebody.
    '   Apologies.
    '
    '   I key'd the detection routine to the MAC address instead of DeviceNames$ since the latter
    '   sometimes returns a nul string and it's also faster. MAC addresses, on the other hand, are
    '   always there.
    '
    '   Note: If a device (printer, network PC or other device is off, nothing will be returned
    '         for that device.
    '
    '   Of course, questions/comments are always welcome. Please post them in the CC forum.
    
    DECLARE FUNCTION SendARP LIB "iphlpapi.dll" ALIAS "SendARP" _
            (BYVAL DestIP AS DWORD, BYVAL SrcIP AS DWORD, pMacAddr AS DWORD, _
            PhyAddrLen AS DWORD) AS DWORD
    '
    DECLARE FUNCTION inet_addr LIB "wsock32.dll" ALIAS "inet_addr" (cp AS ASCIIZ) AS DWORD
    
    DECLARE FUNCTION GetMACaddress(ASCIIZ) AS STRING        '
    DECLARE SUB initialize
                                                            '
        %no_error = 0                                       '
                                                            '
        FUNCTION PBMAIN()                                   '
        LOCAL ipLong   AS LONG                              '
        LOCAL w,x,y,z  AS LONG                              '
        LOCAL flag     AS LONG                              '
        GLOBAL w1, w2  AS LONG                              '
        GLOBAL x1, x2  AS LONG                              '
        GLOBAL y1, y2  AS LONG                              '
        GLOBAL z1, z2  AS LONG                              '
        GLOBAL ini$                                         '
        LOCAL StringIP AS STRING                            '
        LOCAL sMac     AS STRING                            '
        LOCAL tm       AS ASCIIZ * 16                       '
                                                            '
        fi$ = "SafeList.txt"                                '
        OPEN fi$ FOR BINARY AS #1                           ' Just to make sure the file
        CLOSE #1                                            ' exists
                                                            '
        f$ = "###"                                          '
        f1$ = "###,###,###,###"                             '
        COLOR 14,1                                          '
        CLS                                                 '
                                                            '
        ini$ = "who's on my network.ini"                    '
        te$ = DIR$(ini$)                                    '
        IF te$ = "" THEN                                    '<:
        initialize                                          ' |
        ELSE                                                '<:
        OPEN ini$ FOR INPUT AS #1                           ' |
        INPUT #1,te$ : w1 = VAL(te$)                        ' |
        INPUT #1,te$ : w2 = VAL(te$)                        ' |
        INPUT #1,te$ : x1 = VAL(te$)                        ' |
        INPUT #1,te$ : x2 = VAL(te$)                        ' |
        INPUT #1,te$ : y1 = VAL(te$)                        ' |
        INPUT #1,te$ : y2 = VAL(te$)                        ' |
        INPUT #1,te$ : z1 = VAL(te$)                        ' |
        INPUT #1,te$ : z2 = VAL(te$)                        ' |
        CLOSE #1                                            ' |
        END IF                                              '<:
        CLS                                                 '
                                                            '
        FOR w = w1 TO w2                                    '
        FOR x = x1 TO x2                                    '
        FOR y = y1 TO y2                                    '
        FOR z = z1 TO z2                                    '<--Starting address of my home network
                                                            '
    REM *******************************                     '
    REM * Build the string IP address *                     '
    REM *******************************                     '
                                                            '
        StringIP =            USING$(f$,w) + "."            '
        StringIP = StringIP + USING$(f$,x) + "."            '
        StringIP = StringIP + USING$(f$,y) + "."            '
        StringIP = StringIP + USING$(f$,z)                  '
        StringIP = REMOVE$(StringIP," ")                    '
                                                            '
    REM ********************************************************************
    REM * Convert StringIP to a long integer                               *
    REM * Eros Olmi                                                        *
    REM * http://www.powerbasic.com/support/pbforums/showthread.php?t=38093*
    REM ********************************************************************
                                                            '
        IpLong = ((VAL(PARSE$(StringIP, ".", 4))  * _       '
             256 + VAL(PARSE$(StringIP, ".", 3))) * _       '
             256 + VAL(PARSE$(StringIP, ".", 2))) * _       '
             256 + VAL(PARSE$(StringIP, ".", 1))            '
                                                            '
    REM *********************************************************************
    REM * Get the MAC address of the attached device                        *
    REM * John McWilliams                                                   *
    REM * http://www.powerbasic.com/support/pbforums/showthread.php?t=24169 *
    REM *********************************************************************
                                                            '
        tm = StringIP                                       '
        sMAC = GetMACaddress(tm)                            '<== What's the MAC address
                                                            '    of this device?
    REM *********************************************       '
    REM * It's a lot faster getting the device name *       '
    REM * after making sure there's a Mac Address   *       '
    REM * attached it it.                           *       '
    REM *********************************************       '
                                                            '
        IF sMac <> "" THEN                                  '<:
        HOST NAME (ipLong) TO DeviceName$                   ' |
        END IF                                              '<:
                                                            '
        IF DeviceName$ = "" THEN                            '<:
        DeviceName$ = "Unknown Device"                      ' |
        END IF                                              '<:
                                                            '
        PRINT;StringIP ; TAB(20) ; USING$(f1$,iplong) ; _   '
                         TAB(40);DeviceName$;TAB(60);sMac   '
        IF LEN(sMac) <> 17 THEN sMac = ""                   '
                                                            '
        IF sMac <> "" THEN                                  '<--:
        flag = 0                                            '   |
        OPEN fi$ FOR INPUT AS #1                            '   |
        DO UNTIL EOF(1)                                     '<: |
        INPUT #1,t1$ , t2$ , t3$                            ' | | String IP Address
        IF t3$ = sMac THEN flag = 1                         ' | |
        LOOP                                                '<: |
        CLOSE #1                                            '   |
                                                            '   |
    REM *******************************                     '   |
    REM * Match not found. Query user *                     '   |
    REM *******************************                     '   |
        IF flag = 0 THEN                                    '<-:|
        CLS                                                 '  ||
        LOCATE  5,30 : PRINT;StringIP                       '  ||
        LOCATE  7,30 : PRINT;DeviceName$                    '  ||
        LOCATE  9,30 : PRINT;sMac                           '  ||
        LOCATE 13,30 : PRINT;"Not found. Accept? (Y/N)"     '  ||
        DO                                                  '<:||
        WHILE INSTAT = 0 : WEND                             ' |||
        an$ = UCASE$(INKEY$)                                ' |||
        IF an$ = "Y" OR an$ = "N" THEN EXIT LOOP            ' |||
        BEEP                                                ' |||
        LOOP                                                '<:||
                                                            '  ||
        IF an$ = "Y" THEN                                   '<:||
        OPEN fi$ FOR BINARY AS #1                           ' |||
        SEEK #1,LOF(1) + 1                                  ' |||
        PUT$ #1,StringIP + ","                              ' |||
        PUT$ #1,DeviceName$ + ","                           ' |||
        PUT$ #1,sMac + $CRLF                                ' |||
        CLOSE #1                                            ' |||
        END IF                                              '<:||
        END IF                                              '<-:|
        END IF                                              '<--:
                                                            '
                                                            '
        StringIP = ""                                       '
        IPlong = 0                                          '
        DeviceName$ = ""                                    '
        sMac = ""                                           '
                                                            '
        IF INKEY$ = CHR$(27) THEN EXIT FUNCTION             '
                                                            '
        NEXT : NEXT : NEXT : NEXT                           '
        BEEP                                                '
        WAITKEY$                                            '
        END FUNCTION                                        '
                                                            '
                                                            '
    FUNCTION GetMACaddress(szIP AS ASCIIZ) AS STRING        '
                                                            '
        'John McWilliams                                    '
        'http://www.powerbasic.com/support/pbforums/showthread.php?t=24169
        '
        '  Input: IP address from which you want the MAC address
        ' Output: The MAC address as "00-00-00-00-00-00" on success
        '         null string on failure. Bad IP addresses returns a
        '         null string.
        '
        'Depends: win32API.inc, iphlpapi.inc, wsock32.inc
        '
        LOCAL Result        AS LONG
        LOCAL MACbytes      AS LONG
        DIM   ipArray(0)    AS DWORD
        DIM   p             AS BYTE PTR
        '
        FUNCTION = "" : IF LEN(TRIM$(szIP)) = 0 THEN EXIT FUNCTION
        '
        'The first six bytes of the array receive the physical address that corresponds to the IP
        'address specified by szIP. See "SendARP" in MSDN for more info.
        MACbytes = 6  'MACbytes is NOT a statement about Apple Macintosh's
        '
        Result = SendARP(inet_addr(szIP), 0, ipArray(0), MACbytes)
        IF Result = %NO_ERROR THEN   'Success
           p = VARPTR(ipArray(0))
           FUNCTION = HEX$(@p, 2) & "-" & HEX$(@p[1], 2) & "-" & HEX$(@p[2], 2) & "-" & HEX$(@p[3], 2) & _
                      "-" & HEX$(@p[4], 2) & "-" & HEX$(@p[5], 2)
        END IF
    END FUNCTION
    
    SUB initialize
        LOCAL col AS LONG
        CLS
        m$ = "We need to initialize the TCP/IP address numbers. These will be in the form: "
        col = 40 - INT(LEN(m$) / 2)
        LOCATE  3,col : PRINT;m$;
        m$ = "of WWW.XXX.YYY.ZZZ. Each one of these entries will have a start/stop value in"
        LOCATE  5,col : PRINT;m$;
        m$ = "the range of 0 to 255. Please enter them now."
        LOCATE  7,col : PRINT;m$;
    
        LOCATE 10,col : INPUT;"WWW start: ";te$ : w1 = VAL(te$)
        LOCATE 11,col : INPUT;"WWW  stop: ";te$ : w2 = VAL(te$)
        LOCATE 12,col : INPUT;"XXX start: ";te$ : x1 = VAL(te$)
        LOCATE 13,col : INPUT;"XXX  stop: ";te$ : x2 = VAL(te$)
        LOCATE 14,col : INPUT;"YYY start: ";te$ : y1 = VAL(te$)
        LOCATE 15,col : INPUT;"YYY  stop: ";te$ : y2 = VAL(te$)
        LOCATE 16,col : INPUT;"ZZZ start: ";te$ : z1 = VAL(te$)
        LOCATE 17,col : INPUT;"ZZZ  stop: ";te$ : z2 = VAL(te$)
    
        OPEN ini$ FOR BINARY AS #1
        PUT$ #1,STR$(w1) + $CRLF
        PUT$ #1,STR$(w2) + $CRLF
        PUT$ #1,STR$(x1) + $CRLF
        PUT$ #1,STR$(x2) + $CRLF
        PUT$ #1,STR$(y1) + $CRLF
        PUT$ #1,STR$(y2) + $CRLF
        PUT$ #1,STR$(z1) + $CRLF
        PUT$ #1,STR$(z2) + $CRLF
        SETEOF(1)
        CLOSE #1
        END SUB
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

    Comment

    Working...
    X
    😀
    🥰
    🤢
    😎
    😡
    👍
    👎