Link to home
Create AccountLog in
Avatar of Showkatdar
Showkatdar

asked on

VB 6 Code To Send Packet To Network

Is there any way to Write a Programe in VB 6, which could send data packets to the Complete Network and get the desired Information from the Network.
Avatar of Anthony2000
Anthony2000
Flag of United States of America image

Use the Winsock control in VB6.

see http://www.15seconds.com/Issue/010820.htm

If you still need help, just ask additional questions.

When you say "the Complete Network", what do you mean exactly?

Do you want to write your own program to talk to another program you write using the internet? If so, the answer is you can do it using the Winsock control in VB6.
if you want to send some data to all computers in network i suggest you use UDP not TCP.

and if you open visual basic and create a new project and press Ctrl + T and select 'Micrsoft Winsock Control 6.0' and press ok. in the toolbar (left) one new icon will be add. that is winsock. add a winsock to your form y double clicking on last item in the left toolbar. so, you can write these lines of code for form_load (for example)
winsock1.localport = 343 'randomly
winsock1.connect "192.168.0.33"
winsock1.senddata "test"

you see, it's so easy!
regards
Private Sub Form_Load()
Winsock1.LocalPort = 222
Winsock1.Connect "192.168.0.223"
Winsock1.SendData "text for send"
End Sub
 
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim data As String
Winsock1.GetData data
MsgBox data
End Sub
 
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
w.Close
MsgBox Description
End Sub

Open in new window

Avatar of Showkatdar
Showkatdar

ASKER

Dear it is giving me error.Any suggestionz please
Error.jpg
oh, sorry! my bad
you should send data when connection established like this : [code snippet]

this works but i think there is no 192.168.0.223 on your network listening on 222 port!
so i suggest you use this (this is more real test):

'add a textbox (text1) and set its multiline property to true
Private Sub Form_Load()
Text1.Text = ""
Winsock1.Connect "www.google.com", 80
End Sub
 
Private Sub Winsock1_Connect()
Winsock1.SendData "GET / HTTP/1.1" & vbCrLf & "Host: www.google.com" & vbCrLf & vbCrLf
Me.Caption = "data sent"
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim data As String
Winsock1.GetData data
Text1.Text = Text1.Text & data
End Sub
 
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Winsock1.Close
MsgBox Description
End Sub



regards...
Private Sub Form_Load()
Winsock1.LocalPort = 222
Winsock1.Connect "192.168.0.223"
End Sub
 
Private Sub Winsock1_Connect()
Winsock1.SendData "text for send"
Me.Caption = "data sent"
End Sub
 
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim data As String
Winsock1.GetData data
MsgBox data
End Sub
 
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Winsock1.Close
MsgBox Description
End Sub

Open in new window

Dear,

Actually i m System Administrator by Profession and right now i m facing few issues in my network. To solve that issue what i need is to check that there is no computer on in the night, means before leaving office every one shuts down his computer. I cant do it manually on 300+ computers.
So I need to send data packets to all computers in the network not only to a specific  computer, to get this specific information.
Is there any way around???
Send the packet to Network in the mid of night using my computer and see which computer is replying to my ping.
Hope i get appropriate solution
Thank you and regards
well, I suggest you two ways:
1- you can develop an application that listen on specific port and waits for connection request. this application should be run on every computer at night at least. then, you should develop another simple application that try to connect to computers on specific port. if succeed, it's on or else it's off. but this method has a bad point. your first application should be run.

2- this way is so easy to implement and hope you like it :)
you can ping to computers. so, you should develop an application that pings. but this is hard. so, I have a easy way:
you can use windows' ping by visual basic and store it's result in file. look:
IP  = "192.168.0.1"
Call Shell("c:\pinger.bat " & IP, vbHide)

what is pinger.bat? you should create a pinger.bat that contains this line:
ping %1 -n 1 > c:\%1.txt

so, you should develop an application that has a listbox that contains all IPs and in a for loop, you should set IP and call shell

after execution of the application, you will have a lot of text files that their names are IP. so, you should use windows search that search in text files that the application created for "Request timed out"
all of text files that contain "Request timed out" string, are IP of off computers.

hope you understand
regards
But how can i generate ip address using for loop in vb6
no sir! you should add all IPs in a listbox or example
absolutely you should have IP's of computers
regards
something like this i mean
regards
for i= 0 to list1.listcount
IP = list1.list(i)
Call Shell("c:\pinger.bat " & IP, vbHide)
next i

Open in new window

Dear CSecurity,

First of all thank you for you comments.
I tried the way guided me but could not generate ips in for loop. Still i m trying to do it.
but if any idea your good self have, please let me know
Regards
I think you didn't understand. well, first of all you should have all IPs. so, I assume that you have IPs in a text file (I mean assume that you have a text file that contains 300+ IP addresses). well, now you should add all IP addresses from text file to listbox (add a listbox to your project called List1). well, when your listbox (List1) has all IP addresses, should execute my code (I mean for i =0 ....).

again: you should ask them to told their IP address and save them in a text file.

hope help you
regards
Private Sub Form_Load()
'c:\IPs.txt contains all IP addresses in the network
Open "c:\IPs.txt" For Input As #1
Dim str As String
Do While Not EOF(1)
Input #1, str
List1.AddItem str
Loop
Close #1
 
For i = 0 To List1.ListCount
IP = List1.List(i)
Call Shell("c:\pinger.bat " & IP, vbHide)
Next i
 
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of CSecurity
CSecurity
Flag of Iran, Islamic Republic of image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer