Michael, I am getting this error-- see attached image.
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
Michael, I am getting this error-- see attached image.
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
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
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:
Let me know if it worksUses "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
Ciao
Eros
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
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
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
Bookmarks