Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Netstat results to db 1

Status
Not open for further replies.

advait75

Programmer
Oct 5, 2002
48
IN
Hi,
Can somebody please give me source code for writing the results of a netstat command, to a database using VB6.
I am having problems as the output of netstat from the command line is not properly formatted.
Thanks and best regards,
Advait
 
You can have the command prompt pipe the netstat output to a text file:

netstat -a>D:\Temp\Netstat.txt

Then you can parse the text file for the info you want in the database.

Is this what you want to do?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
I tried parsing the text file and put it ino the database. However the output from a netstat command to a file is not formatted and so I was facing errors. Any ida how to format the output.
Regards
 
Here is how u can do it.
I copy the code.

Code for project1.vbp
Code:
Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\WINDOWS\system32\stdole2.tlb#OLE Automation
Reference=*\G{C063ECA3-E7FC-4C27-9896-2AA5C6EEA3A1}#1a.0#0#..\..\..\WINDOWS\system32\VB5_Split_Replace_Buscar.dll#VB5_Split_Replace_Buscar
Form=Form1.frm
Startup="Form1"
Command32=""
Name="Proyecto1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
ThreadPerObject=0
MaxNumberOfThreads=1

[MS Transaction Server]
AutoRefresh=1

Code for form1
Code:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   5940
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7545
   LinkTopic       =   "Form1"
   ScaleHeight     =   5940
   ScaleWidth      =   7545
   StartUpPosition =   3  'Windows Default
   Begin VB.ListBox List1 
      Height          =   2790
      Index           =   4
      Left            =   5700
      TabIndex        =   3
      Top             =   135
      Width           =   1785
   End
   Begin VB.ListBox List1 
      Height          =   2790
      Index           =   3
      Left            =   3825
      TabIndex        =   2
      Top             =   150
      Width           =   1785
   End
   Begin VB.ListBox List1 
      Height          =   2790
      Index           =   2
      Left            =   1890
      TabIndex        =   1
      Top             =   165
      Width           =   1785
   End
   Begin VB.ListBox List1 
      Height          =   2790
      Index           =   1
      Left            =   60
      TabIndex        =   0
      Top             =   180
      Width           =   1785
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
'Since I use VB5 I made my own replace,split command in a DLL
Dim rep As replace
Set rep = New replace
Dim netstatline As String
'Read first lines (header)
Open "c:\a.txt" For Input As 1
For i = 1 To 4
Line Input #1, vars
Next i
Do
Line Input #1, netstatline
tmpvar = rep.Split(netstatline, " ")
columnnumber = 0
For i = 1 To UBound(tmpvar)
If tmpvar(i) <> "" Then
columnnumber = columnnumber + 1
List1(columnnumber).AddItem tmpvar(i)
End If
Next i
Loop Until EOF(1)

End Sub

Remember to remove this lines:
Dim rep As replace
Set rep = New replace
And the reference to the DLL, since I use vb5 I made my own split & replace DLL.

Hope it helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top