Results 1 to 7 of 7

Thread: NetMask question

  1. #1
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Question NetMask question

    My knowledge of networking is quite limited and I wanted to know the netmask for a project I am working on so I came up with the script below.

    Can I have some feedback on this, is it correct ?

    I removed the code be it was rubbish.
    Last edited by Michael Clease; 27-10-2013 at 23:31.
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  2. #2
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404
    Michael, I am getting this error-- see attached image.
    Attached Images Attached Images

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    I think the error can be fixed by renaming mynetmask to mynet at line 10.

    Mike - I can't confirm whether it is correct or not, my knowledge of networking is as good as my knowledge of quantum mechanics...


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159
    you are correct, it was a last minute rename of a variable without running the script.

    I fixed it now.

    It is a nonsense answer I need to look for an api solution but its evading me at the moment, i'm sure its something to do with an ip class somewhere.
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    56
    Posts
    8,774
    Rep Power
    10
    Michael,

    please get attached new thinBasic_iNet.dll that will be present in next release. Copy it into \thinBasic\Lib\ directory replacing your current one.

    I've added a couple of new functions that hopefully will solve the problem:
    • INet_GetInterfaces returns the number of network interfaces present in your machine
    • iNet_GetSubNet(index) will return the subnet mask of a particulat interface number


    Example:
    Uses "inet"Uses "Console"
    
    
    Long lCount
    
    
    PrintL "Number of interfaces present:", INET_GetInterfaces
    PrintL "--------------------------------------"
    
    
    For lCount = 1 To INET_GetInterfaces
      PrintL lCount, INET_GetIp(lCount),  inet_GetSubNet(lCount)
    Next
    
    
    PrintL "---Press a key to finish--------------"
    WaitKey
    
    Let me know if it works

    Ciao
    Eros
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159
    I will test the code tomorrow, I can see some enhancements that could be added but I will let you know if I have been blown over to France by these winds.
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  7. #7
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159
    Thanks Eros it worked very well, below is what I had found out (with help from PB forums)

    Uses "CONSOLE"
    
    
    '// Definitions and structures used by getnetworkparams and getadaptersinfo apis
    
    
    %MAX_ADAPTER_DESCRIPTION_LENGTH = 128   ' // arb.
    %MAX_ADAPTER_NAME_LENGTH        = 256   ' // arb.
    %MAX_ADAPTER_ADDRESS_LENGTH     = 8     ' // arb.
    %ERROR_BUFFER_OVERFLOW            = 111
    %ERROR_SUCCESS                    = 0     
    
    
    Type IP_ADDRESS_STRING
       sString As String * 4 * 4   ' char String[4 * 4]
    End Type
    
    
    Type IP_MASK_STRING
       sString As String * 4 * 4   ' char String[4 * 4]
    End Type
    
    
    '//
    '// IP_ADDR_STRING - store an IP address with its corresponding subnet mask,
    '// both as dotted decimal strings
    '//
    
    
    Type IP_ADDR_STRING
       pNext     As IP_ADDR_STRING Ptr   ' struct _IP_ADDR_STRING* Next
       IpAddress As IP_ADDRESS_STRING    ' IP_ADDRESS_STRING IpAddress
       IpMask    As IP_MASK_STRING       ' IP_MASK_STRING IpMask
       Context   As DWord                ' DWORD Context
    End Type
    '//
    '// ADAPTER_INFO - per-adapter information. All IP addresses are stored as
    '// strings
    '//
    Type tIP_ADAPTER_INFO
       pNext               As tIP_ADAPTER_INFO Ptr
       ComboIndex          As DWord
       AdapterName         As String * (%MAX_ADAPTER_NAME_LENGTH + 4)
       Description         As String * (%MAX_ADAPTER_DESCRIPTION_LENGTH + 4)
       AddressLength       As DWord
       bAddress(%MAX_ADAPTER_ADDRESS_LENGTH - 1) As Byte
       Index               As DWord
       uType               As DWord
       DhcpEnabled         As DWord
       CurrentIpAddress    As IP_ADDR_STRING Ptr
       IpAddressList       As IP_ADDR_STRING
       GatewayList         As IP_ADDR_STRING
       DhcpServer          As IP_ADDR_STRING
       HaveWins            As Long
       PrimaryWinsServer   As IP_ADDR_STRING
       SecondaryWinsServer As IP_ADDR_STRING
       LeaseObtained       As Long
       LeaseExpires        As Long
    End Type
    
    
    
    
    Declare Function GetAdaptersInfo Lib "iphlpapi.dll" Alias "GetAdaptersInfo" ( _
       ByRef pAdapterInfo As tIP_ADAPTER_INFO, _  ' __out PIP_ADAPTER_INFO pAdapterInfo
       ByRef pOutBufLen As DWord _                ' __in_out PULONG pOutBufLen
     ) As DWord                                   ' DWORD
    
    
    
    
    Dim ADAPT       As String
    Dim Adapters(1) As tIP_ADAPTER_INFO
    Dim Counter     As Long 
    
      adapt = getdg(Adapters)
    
      For Counter = 1 To UBound(Adapters)  
        PrintL "Adapter"+Counter+"  Adapter Name = "+Trim$(Adapters(Counter).AdapterName, $NUL)
        PrintL "Adapter"+Counter+"  Description = "+Trim$(Adapters(Counter).Description, $NUL)
    
        PrintL "Adapter"+Counter+"  Gateway address = "+Trim$(Adapters(Counter).Gatewaylist.Ipaddress.sString, $NUL)
        PrintL "Adapter"+Counter+"  IP address = "+Trim$(Adapters(Counter).IpAddressList.Ipaddress.sString, $NUL)
        PrintL "Adapter"+Counter+"  Netmask = "+Trim$(Adapters(Counter).IpAddressList.IPmask.sString, $NUL)+$CRLF
      Next
    
    
      PrintL "---Press a key to finish--------------"
      WaitKey
             
    
    
    Function GETDG(ByRef AdapterArray) As String
      Local cbRequired          As DWord
      Local AdapterCount        As DWord'  Value = 1
    
      If GetAdaptersInfo(ByVal 0, cbRequired)=%ERROR_BUFFER_OVERFLOW Then
        AdapterCount = cbRequired \ SizeOf(tIP_ADAPTER_INFO)
        ReDim AdapterArray(AdapterCount)
        If GetAdaptersInfo(ByVal VarPtr(AdapterArray(1)), cbRequired) = %ERROR_SUCCESS Then
        End If
      End If
    
    
     End Function
    '--------------------------------------
    
    Last edited by Michael Clease; 29-10-2013 at 15:42.
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

Similar Threads

  1. Question of the day ;)
    By Petr Schreiber in forum thinBasic General
    Replies: 8
    Last Post: 23-08-2010, 19:58
  2. C to TB question
    By Michael Clease in forum Other languages
    Replies: 2
    Last Post: 03-06-2010, 12:11
  3. gdi question
    By Lionheart008 in forum UI (User Interface)
    Replies: 6
    Last Post: 07-12-2009, 19:31
  4. UDT question
    By sandyrepope in forum thinBasic General
    Replies: 3
    Last Post: 18-02-2008, 22:33
  5. m15 question
    By kryton9 in forum M15 file format
    Replies: 4
    Last Post: 20-06-2007, 20:18

Members who have read this thread: 1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •