Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: имя активного I-net соединения Добавлено: 19.05.04 01:24  

Автор вопроса:  Justas  | Web-сайт: justas.newmail.ru | ICQ: 259418212 

Всем привет.

Народ, вот какой вопрос:
на машине настроено 3 интернет-соединения, юзер может выходить в интернет под любым из них. (хочу заблокировать одно из соединений.) Как узнать что машина в коннекте я себе представляю, а вот как узнать имя текущего соединения? Помню что где-то здесь уже такое видел, только искать долго не получается (с интернетом проблемы :((   )

Ответить

  Ответы Всего ответов: 6  

Номер ответа: 1
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #1
Добавлено: 19.05.04 12:24

ASM

.386
.model flat, stdcall
option casemap :none ; case sensitive

 

include windows.inc
include user32.inc
include kernel32.inc
include rasapi32.inc
include oleaut32.inc

 

includelib user32.lib
includelib kernel32.lib
includelib rasapi32.lib
includelib oleaut32.lib

 

 

 

.data?
hInstance dd ?
lpRasConn RASCONN 100h dup()

 

.code
start:

 

LibMain proc hInstDLL:DWORD, reason:DWORD, unused:DWORD
.if reason == DLL_PROCESS_ATTACH
push hInstDLL
pop hInstance

 

mov lpRasConn.dwSize, 412 ; sizeof RASCONN + 1
mov eax, TRUE
.endif
ret
LibMain Endp

 

UpdateData proc
Local lpcb:DWORD, lpcConnections:DWORD

 

mov lpcb, 412 * 100h
invoke RasEnumConnections, addr lpRasConn, addr lpcb, addr lpcConnections
ret
UpdateData endp

 

IsConnected proc
.If lpRasConn.hrasconn == 0h
mov eax, FALSE
.else
mov eax, TRUE
.endif
ret
IsConnected endp

 

GetConName proc
lea eax, lpRasConn.szEntryName
ret
GetConName endp

 

GetDeviceName proc
lea eax, lpRasConn.szDeviceName
ret
GetDeviceName endp

 

GetDeviceType proc
invoke CharLower, addr lpRasConn.szDeviceType
ret
GetDeviceType endp

 

GetNumInfo proc
.data
all db "ALL",0
.code
lea eax, all
ret
GetNumInfo endp
End start


PB

#Compile Dll "AuthGCS.dll"
#Dim All
#Include "RAS32.INC"
#Include "WIN32API.INC"

 

Global g_hInstance As Long
Global lpRasConn() As RASCONN
Global sBuffer As String

 

Function WinErrorMsg(ByVal dError As Dword) As String

 

Local pBuffer As Asciiz Ptr
Local ncbBuffer As Dword

 

ncbBuffer = FormatMessage( _
%FORMAT_MESSAGE_ALLOCATE_BUFFER _
Or %FORMAT_MESSAGE_FROM_SYSTEM _
Or %FORMAT_MESSAGE_IGNORE_INSERTS, _
ByVal %NULL, _
dError, _
ByVal MAKELANGID(%LANG_NEUTRAL, %SUBLANG_DEFAULT), _
ByVal VarPtr(pBuffer), _
0, _
ByVal %NULL)

 

If ncbBuffer Then
Function = Peek$(pBuffer, ncbBuffer)
LocalFree pBuffer
End If

 

End Function

 

' ---------------------------- Code -----------------------------------

 

Sub UpdateData Alias "UpdateData"() Export
Dim nRet As Long
Dim lpcb As Dword, lpcConnections As Dword

 

ReDim lpRasConn(255)

 

lpRasConn(0).dwSize = SizeOf(RASCONN)
lpcb = SizeOf(RASCONN)

 

nRet = RasEnumConnections(lpRasConn(0), lpcb, lpcConnections)
If Not nRet = 0 Then
MsgBox WinErrorMsg(nRet)
End If
End Sub

 

Function IsConnected Alias "IsConnected"() Export As Long
Function = Not (lpRasConn(0).hRasConn = 0&)
End Function

 

Function GetConName Alias "GetConName"() Export As String
Function = lpRasConn(0).szEntryName
End Function

 

Function GetDeviceName Alias "GetDeviceName"() Export As String
GetDeviceName = lpRasConn(0).szDeviceName
End Function

 

Function GetDeviceType Alias "GetDeviceType"() Export As String
GetDeviceType = LCase$(lpRasConn(0).szDeviceTYPE)
End Function

 

Function GetNumInfo Alias "GetNumInfo"() Export As String
Function = "All"
End Function

 

' ----------------------------- Инициализация dll библиотеки -----------------------------------

 

Function DllMain(ByVal hInstance As Long, ByVal Reason As Long, ByVal Reserved As Long) As Long
If Reason = %DLL_PROCESS_ATTACH Then
g_hInstance = hInstance
End If

 

Function = 1&
End Function


VB

Option Explicit
Private Declare Function RasEnumConnections Lib "rasapi32.dll" Alias "RasEnumConnectionsA" (lpRasconn As Any, lpcb As Long, lpcConnections As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

 

Private Type VBRASCONN
hRasConn As Long
sEntryName As String
sDeviceType As String
sDeviceName As String
sPhonebook As String
lngSubEntry As Long
guidEntry(15) As Byte
End Type
Private Declare Function GetProfStr Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal sSection As String, ByVal sKey As Any, ByVal sDefault As String, ByVal sValue As String, ByVal nSize As Long, ByVal sFileName As String) As Long
Private sConName As String, bIsConnected As Boolean, sDeviceName As String, sDeviceType As String

 

Public Sub UpdateData()
Dim rtn As Long, b() As Byte, ras_i As Long
Dim aLens As Variant, dwSize As Long
Dim lpcb As Long, lpConns As Long
Dim aVBRasConns() As VBRASCONN

bIsConnected = False
sConName = vbNullString
sDeviceName = vbNullString
sDeviceType = vbNullString

ReDim b(3)
aLens = Array(692&, 676&, 412&, 32&)

 

For ras_i = 0 To 3
dwSize = aLens(ras_i)
Call CopyMemory(b(0), dwSize, &H4): lpcb = 4
rtn = RasEnumConnections(b(0), lpcb, lpConns)
If Not rtn = 632 And Not rtn = 610 Then Exit For
Next
If lpConns = 0 Then Exit Sub

lpcb = dwSize * lpConns
ReDim b(lpcb - 1)
Call CopyMemory(b(0), dwSize, &H4)
Call RasEnumConnections(b(0), lpcb, lpConns)

ReDim aVBRasConns(lpConns - 1)
For ras_i = 0 To lpConns - 1
With aVBRasConns(ras_i)
Call CopyMemory(.hRasConn, b(ras_i * dwSize + 4), &H4)
If dwSize = 32& Then
Call Byte2Str(.sEntryName, b(ras_i * dwSize + 8), 21&)
Else
Call Byte2Str(.sEntryName, b(ras_i * dwSize + 8), 257&)
Call Byte2Str(.sDeviceType, b(ras_i * dwSize + 265), 17&)
Call Byte2Str(.sDeviceName, b(ras_i * dwSize + 282), 129&)
If dwSize > 412& Then
Call Byte2Str(.sPhonebook, b(ras_i * dwSize + 411), 260&)
Call Byte2Str(.lngSubEntry, b(ras_i * dwSize + 672), 4)
If dwSize > 676& Then Call CopyMemory(.guidEntry(0), b(ras_i * dwSize + 676), 16)
End If
End If
bIsConnected = True
sConName = .sEntryName<

Ответить

Номер ответа: 2
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #2
Добавлено: 19.05.04 12:26

Чуток не уместилось... VB

Option Explicit
Private Declare Function RasEnumConnections Lib "rasapi32.dll" Alias "RasEnumConnectionsA" (lpRasconn As Any, lpcb As Long, lpcConnections As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

 

Private Type VBRASCONN
hRasConn As Long
sEntryName As String
sDeviceType As String
sDeviceName As String
sPhonebook As String
lngSubEntry As Long
guidEntry(15) As Byte
End Type
Private Declare Function GetProfStr Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal sSection As String, ByVal sKey As Any, ByVal sDefault As String, ByVal sValue As String, ByVal nSize As Long, ByVal sFileName As String) As Long
Private sConName As String, bIsConnected As Boolean, sDeviceName As String, sDeviceType As String

 

Public Sub UpdateData()
Dim rtn As Long, b() As Byte, ras_i As Long
Dim aLens As Variant, dwSize As Long
Dim lpcb As Long, lpConns As Long
Dim aVBRasConns() As VBRASCONN

bIsConnected = False
sConName = vbNullString
sDeviceName = vbNullString
sDeviceType = vbNullString

ReDim b(3)
aLens = Array(692&, 676&, 412&, 32&)

 

For ras_i = 0 To 3
dwSize = aLens(ras_i)
Call CopyMemory(b(0), dwSize, &H4): lpcb = 4
rtn = RasEnumConnections(b(0), lpcb, lpConns)
If Not rtn = 632 And Not rtn = 610 Then Exit For
Next
If lpConns = 0 Then Exit Sub

lpcb = dwSize * lpConns
ReDim b(lpcb - 1)
Call CopyMemory(b(0), dwSize, &H4)
Call RasEnumConnections(b(0), lpcb, lpConns)

ReDim aVBRasConns(lpConns - 1)
For ras_i = 0 To lpConns - 1
With aVBRasConns(ras_i)
Call CopyMemory(.hRasConn, b(ras_i * dwSize + 4), &H4)
If dwSize = 32& Then
Call Byte2Str(.sEntryName, b(ras_i * dwSize + 8), 21&)
Else
Call Byte2Str(.sEntryName, b(ras_i * dwSize + 8), 257&)
Call Byte2Str(.sDeviceType, b(ras_i * dwSize + 265), 17&)
Call Byte2Str(.sDeviceName, b(ras_i * dwSize + 282), 129&)
If dwSize > 412& Then
Call Byte2Str(.sPhonebook, b(ras_i * dwSize + 411), 260&)
Call Byte2Str(.lngSubEntry, b(ras_i * dwSize + 672), 4)
If dwSize > 676& Then Call CopyMemory(.guidEntry(0), b(ras_i * dwSize + 676), 16)
End If
End If
bIsConnected = True
sConName = .sEntryName
sDeviceName = .sDeviceName
sDeviceType = .sDeviceType
End With
Next
End Sub

 

Public Function IsConnected() As Boolean 'Подключены ли мы к инету
IsConnected = bIsConnected
End Function

 

Public Function GetConName() As String 'Получаем имя текущего соединения
GetConName = sConName
End Function

 

Public Function GetDeviceType() As String 'Тип устройства
GetDeviceType = sDeviceType
End Function

 

Public Function GetDeviceName() As String 'Имя устройства
GetDeviceName = sDeviceName
End Function

 

Private Function Byte2Str(bPos As Byte, lngMaxLen As Long) As String
Byte2Str = String$(lngMaxLen + &H1, &H0)
Call CopyMemory(ByVal Byte2Str, bPos, lngMaxLen)

Byte2Str = Left$(Byte2Str, InStr(Byte2Str, vbNullChar) - &H1)
End Function


Пиши на любом... Вот только соединение во время дозвона самое раннее определить только при начале аутентификации :(

Ответить

Номер ответа: 3
Автор ответа:
 Calhoon



ICQ: 789764 

Вопросов: 90
Ответов: 230
 Web-сайт: 4elovekssn.blog.ru
 Профиль | | #3
Добавлено: 19.05.04 15:12

to sne: какой ужас!!!!

тут, на сайте (http://www.vbnet.ru/faq/showtopic.asp?id=70):

Private Const RAS_MAXENTRYNAME As Integer = 256
Private Const RAS_MAXDEVICETYPE As Integer = 16
Private Const RAS_MAXDEVICENAME As Integer = 128
Private Const RAS_RASCONNSIZE As Integer = 412
Private Type RASCONN
dwSize As Long
hRasConn As Long
szEntryName(RAS_MAXENTRYNAME) As Byte
szDeviceType(RAS_MAXDEVICETYPE) As Byte
szDeviceName(RAS_MAXDEVICENAME) As Byte
End Type
Private Declare Function RasEnumConnections Lib "rasapi32.dll" Alias "RasEnumConnectionsA" (udtRasConn As Any, lpcb As Long, lpcConnections As Long) As Long

Private Sub Command1_Click()
Dim udtRasConn(255) As RASCONN, countConn As Long
Dim Ret As Long, b As Long
udtRasConn(0).dwSize = RAS_RASCONNSIZE
Ret = RasEnumConnections(udtRasConn(0), RAS_MAXENTRYNAME * udtRasConn(0).dwSize, countConn)
If Ret = 0 Then
For b = 0 To countConn - 1
MsgBox "Текущее соединение: " & StrConv(udtRasConn(b).szEntryName(), vbUnicode)
Next b
End If
End Sub

Ответить

Номер ответа: 4
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #4
Добавлено: 19.05.04 15:53

:))) Это оно и есть, только с кучей функций и оформлена в виде длл (на 3-х языках, выбирай любой :)

Ответить

Номер ответа: 5
Автор ответа:
 Calhoon



ICQ: 789764 

Вопросов: 90
Ответов: 230
 Web-сайт: 4elovekssn.blog.ru
 Профиль | | #5
Добавлено: 20.05.04 04:22
to sne: мог бы и на 5 языках написать...

Ответить

Номер ответа: 6
Автор ответа:
 Justas



ICQ: 259418212 

Вопросов: 24
Ответов: 325
 Web-сайт: justas.newmail.ru
 Профиль | | #6
Добавлено: 20.05.04 07:12

всем двум большущее пасибо!

з/ы

риторика: и как раньше народ без интернета жил?

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам