Announcement

Collapse
No announcement yet.

How do you determine computer network ID?

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

  • How do you determine computer network ID?

    I'd appreciate a bit of help (or maybe a lot of help :gurney on how to determine a computer's network ID with a PBCC program on that computer. I'd also like to be able to determine the network ID of all of the computers on the network that are connected to the computer on which the program is running.

    Thank you in advance for any suggestions.

  • #2
    see the GetComputerName() API.

    Once your application has the name of the PC it is running on you just need to return it to some collector, either through a log file, TCP connection, etc. That's all up to you how you want to implement it.
    <b>George W. Bleck</b>
    <img src='http://www.blecktech.com/myemail.gif'>

    Comment


    • #3
      If I'm reading you right, this may help:

      http://www.powerbasic.com/support/pb...ad.php?t=38098

      The source got kinda scrambled during the transition from the old board to the new but you should be able to fix it. If not, PM with your e-mail and I'll send it to you.
      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


      • #4
        I think Mel is more spot on.. I may have read your post bass ackwards :laugh:
        <b>George W. Bleck</b>
        <img src='http://www.blecktech.com/myemail.gif'>

        Comment


        • #5
          Originally posted by George Bleck View Post

          see the GetComputerName() API ...

          Originally posted by Mel Bishop View Post

          If I'm reading you right, this may help:

          http://www.powerbasic.com/support/pb...ad.php?t=38098 ...
          First, let me apologize for my sloppy post. It was late, but that's a lame excuse. A more explicit request for help would have included the following information: Windows XP Pro, PBCC 5.01. In addition, I should have used the term computer name rather than network ID.

          Much thanks to George & Mel for their posts. I believe George's suggestion to use GetComputerName() will do the trick for identifying the local computer name. I also believe that Mel's program -- at the provided link -- will identify the computer names of remote computers -- instead of the MACs -- with a slight modification. I will report my results on this thread.
          Last edited by Walter Henn; 21 Mar 2009, 03:49 PM. Reason: Replaced share name with computer name.

          Comment


          • #6
            Originally posted by José Roca View Post
            Try this one.
            Code:
             
            #INCLUDE "WIN32API.INC" 'added to Jose's code by another poster
            ' --------------------------------------------------------------------------
            ' Retrieves the computer name of the current system.
            ' --------------------------------------------------------------------------
            FUNCTION DS_GetComputerName () AS STRING
               LOCAL lResult AS LONG
               LOCAL buff    AS ASCIIZ * %MAX_COMPUTERNAME_LENGTH '15 bytes
               LOCAL nlen    AS DWORD
               nlen = SIZEOF(buff)
               lResult = GetComputerName(buff, nlen)
               IF lResult <> 0 THEN FUNCTION = buff
            END FUNCTION
            Based on George Bleck's suggestion to use GetComputerName(), I found Jose Roca's code shown above on the forum and was able to successfully get the local computer's name.

            I'm very grateful to George Bleck and Jose Roca for providing the solution to determining a local computer's name.

            --- Walter
            Last edited by Walter Henn; 21 Mar 2009, 03:44 PM. Reason: Replaced share name with computer name.

            Comment


            • #7
              There is also the built-in HOST NAME statement available..
              Rgds, Dave

              Comment


              • #8
                Thanks for your suggestion, Dave. It turns out to be a feature of Mel's program.

                A big thanks to Mel Bishop for his program, Who's on My Network (v2.0). :goldcup: It worked perfectly and identified all the computer names on the network, including the local computer's name. It also identifies the IP and MAC address of all of the devices on the network and produces an alert when an unrecognized device is encountered (the legit devices are accepted by the user when identified, and then stored in a file).

                With Mel's approval, I am including the new version (v2.0) below:


                Code:
                 
                '   Who's on my network version 2.0
                '      by Mel Bishop                                 '
                '   v 1.5 = Modified so you can specify your own TCP/IP ranges.     '
                '   v 2.0 = Did some cosmetic updates.                              '
                '           Instituted a loop for checking via COMMAND$.            '
                '               0 = Infinite loop                                   '
                '              >0 = Number of times to loop                         '
                '                                                                   '
                '   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.                                           '
                                                                                    '
                #INCLUDE "WIN32API.INC"                                             '
                                                                                    '
                    DECLARE SUB MinimizeWindow                                      '
                    DECLARE SUB RestoreWindow                                       '
                                                                                    '
                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                                              '
                DECLARE SUB Delay(DelayTime AS SINGLE)                              '
                                                                                    '
                    %no_error = 0                                                   '
                                                                                    '
                FUNCTION PBMAIN()                                                   '
                    LOCAL ipLong      AS LONG                                       '
                    LOCAL x           AS LONG
                    LOCAL flag, p     AS LONG                                       '
                    GLOBAL cRow, cCol AS LONG                                       '
                    GLOBAL Abort      AS LONG                                       '
                    GLOBAL AbortNbr   AS LONG                                       '
                    LOCAL StringIP    AS STRING                                     '
                    LOCAL sMac        AS STRING                                     '
                    LOCAL tm          AS ASCIIZ * 16                                '
                    GLOBAL ini$                                                     '
                    GLOBAL Hndl AS DWORD                                            '
                    CONSOLE SCREEN 26, 80                                           '
                    Hndl = GetForegroundWindow                                      '
                                                                                    '
                '    MinimizeWindow                                                  '
                    fi$ = "SafeList.txt"                                            ' Make sure the file exists
                    OPEN fi$ FOR BINARY AS #1                                       '
                    CLOSE #1                                                        '
                                                                                    '
                    f$ = "###"                                                      '
                    f1$ = "###,###,###,###"                                         '
                    CONSOLE SCREEN 25,80                                            '
                    COLOR 14,1                                                      '
                    CLS                                                             '
                    nr$ = "Name not returned"                                       '
                    ini$ = "who's on my network.ini"                                '
                                                                                    '
                    cRow = 3                                                        '
                                                                                    '
                    t$ = COMMAND$                                                   '
                    IF t$ = "" THEN                                                 '<:
                    abort = 1                                                       ' | Default to loop
                    ELSE                                                            '<: one time.
                    abort = VAL(t$)                                                 ' |
                    END IF                                                          '<:
                                                                                    '
                    DO                                                              '<----:
                    cRow = 3                                                        '     |
                    CLS                                                             '     |
                    LOCATE  1, 1 : PRINT;"TCP/IP Address";                          '     |
                    LOCATE  1,22 : PRINT;"Long # Address";                          '     |
                    LOCATE  1,38 : PRINT;"Device Name";                             '     |
                    LOCATE  1,60 : PRINT;"MAC Address";                             '     |
                    LOCATE  2, 1 : PRINT;STRING$(80,"=");                           '     |
                                                                                    '     |
                    BaseIP$ = "192.168.1."                                          '     |
                                                                                    '     |
                    FOR x = 1 TO 255                                                '<---:|
                                                                                    '    ||
                REM *******************************                                 '    ||
                REM * Build the string IP address *                                 '    ||
                REM *******************************                                 '    ||
                                                                                    '    ||
                    te$ = BaseIP$ + USING$("###",x)                                 '    ||
                    StringIP = REMOVE$(te$," ")                                     '    ||
                                                                                    '    ||
                    LOCATE cRow,1                                                   '    ||
                    PRINT;"Checking: " + StringIP                                   '    ||
                                                                                    '    ||
                REM ******************************************************************** ||
                REM * Convert StringIP to a long integer                               * ||
                REM * Eros Olmi                                                        * ||
                REM * http://www.powerbasic.com/support/pb...ad.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/pb...ad.php?t=24169 *||
                REM *********************************************************************||
                                                                                    '    ||
                    tm = StringIP                                                   '    ||
                    sMAC = GetMACaddress(tm)                                        '    ||What's the MAC address
                    IF LEN(sMac) <> 17 THEN sMac = ""                               '    ||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 te$                                       '  | ||
                    p = INSTR(te$,".")                                              '  | ||
                    IF p > 0 THEN                                                   '<:| ||
                    DeviceName$ = LEFT$(te$,p-1)                                    ' || ||
                    ELSE                                                            '<:| ||
                    DeviceName$ = te$                                               ' || ||
                    END IF                                                          '<:| ||
                    END IF                                                          '<-: ||
                                                                                    '    ||
                    IF DeviceName$ = "" THEN                                        '<:  ||
                    DeviceName$ = nr$                                               ' |  ||
                    END IF                                                          '<:  ||
                                                                                    '    ||
                    IF sMac <> "" THEN                                              '<--:||
                    LOCATE cRow, 1                                                  '   |||
                    PRINT;StringIP ; TAB(20) ; USING$(f1$,iplong) ; _               '   |||
                                     TAB(38);DeviceName$ ; _                        '   |||
                                     TAB(60);sMac                                   '   |||
                    INCR cRow                                                       '   |||
                    IF cRow = 26 THEN cRow = 3                                      '   |||
                                                                                    '   |||
                    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                                                '<-:|||
                    RestoreWindow                                                   '  ||||
                    winbeep 3000,50                                                 '  ||||
                    PCOPY 1,2                                                       '  ||||
                    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                                                            '<:||||
                    PCOPY 2,1                                                       '  ||||
                    MinimizeWindow                                                  '  ||||
                                                                                    '  ||||
                    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 x                                                          '<---:|
                                                                                    '     |
                    IF abort > 0 THEN                                               '<:   |
                    INCR abortnbr                                                   ' |   |
                    IF abortnbr => abort THEN EXIT LOOP                             ' |   |
                    delay 60                                                        ' |   | 5-minute delay
                    END IF                                                          '<:   | between.
                    IF abort = 0 THEN delay 60                                      '     |
                    LOOP                                                            '<----:
                                                                                    '
                    LOCATE cRow, 1                                                  '
                    PRINT;SPACE$(80)                                                '
                    LOCATE crow,29                                                  '
                    COLOR 0,7                                                       '
                    PRINT;" Done. Press any key. ";                                 '
                    COLOR 14,1                                                      '
                    WAITKEY$                                                        '
                    END FUNCTION                                                    '
                                                                                    '
                SUB Delay(DelayTime AS SINGLE)                                      '   Delay time is in seconds
                    LOCAL StartTime  AS DOUBLE                                      '
                    LOCAL EndTime    AS DOUBLE                                      '   Time to finish
                                                                                    '
                    StartTime = TIMER                                               '
                    EndTime = StartTime + DelayTime                                 '   Add the delay.
                                                                                    '
                    IF EndTime > 86400 THEN                                         '<: Wrap-Around
                    EndTime = EndTime - 86400                                       ' | at midnight.
                    END IF                                                          '<:
                                                                                    '
                    LOCATE crow,1                                                   '
                    PRINT;SPACE$(80);                                               '
                    LOCATE cRow, 35                                                 '
                    COLOR 0,7                                                       '
                    PRINT;" " + TIME$ + " ";                                        '
                    COLOR 14,1                                                      '
                    DO UNTIL StartTime => EndTime                                   '   Keep looping until.....
                    StartTime = TIMER                                               '
                    IF TIME$ <> oldtime$ THEN                                       '<:
                    oldtime$ = TIME$                                                ' |
                    LOCATE cRow + 1,35                                              ' |
                    COLOR 0,7                                                       ' |
                    PRINT;" " + TIME$ + " ";                                        ' |
                    COLOR 14,1                                                      ' |
                    END IF                                                          '<:
                                                                                    '
                    SLEEP 0                                                         '
                    LOOP                                                            '
                    END SUB                                                         '
                                                                                    '
                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 is NOT a statement about Apple Macintosh's            '
                    MacBytes = 6                                                    '
                    '                                                               '
                    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
                 
                 
                 
                 
                    END SUB                                                         '
                 
                SUB MinimizeWindow
                    SendMessage Hndl, %WM_SYSCOMMAND, %SC_MINIMIZE, 0
                    END SUB
                 
                SUB RestoreWindow
                    SendMessage Hndl, %WM_SYSCOMMAND, %SC_RESTORE , 0
                    END SUB
                Last edited by Walter Henn; 21 Mar 2009, 03:51 PM. Reason: Replaced share name with computer name.

                Comment


                • #9
                  Thanks, that will come in handy for me at work because I think one of the satellite network devices is not obeying the DHCP rules and is self allocating it's own IP address based on what IT'S sniffing on the network. Nothing like getting a random popup from the workstation you're on stating that your IP address is suddenly conflicting with another IP address on the network.
                  Furcadia, an interesting online MMORPG in which you can create and program your own content.

                  Comment

                  Working...
                  X