Spreading throught the network

This is a discussion on Spreading throught the network within the Networking/Device Communication forums, part of the General Programming Boards category; Hello, I'm new to network and socket programming, I code in C++. I've had a try previously at sockets, but ...

  1. #1
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209

    Spreading throught the network

    Hello,

    I'm new to network and socket programming, I code in C++. I've had a try previously at sockets, but I couldn't understand it, so I don't have the basic theory. My current problem is this : I'd like to be able to pass a file through a LAN so that I can create files onto other computers on this LAN. I am aware that this sounds suspiciously like writing a virus, but this is not my intention, I want to begin to write a program to update my files from one computer to another as we have three on our home network. I am unsure about searching for files, but if I can type the filename, I want this program to copy the file onto my other computers. If anyone could give me tips on where to start, and how things happen, I'd be very grateful.
    Thank you,
    Korhedron

  2. #2
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    *cough* google *cough*

    You are looking for an implimentation of the FTP protocol :

    www.w3.org/Protocols/rfc959/Overview.html

  3. #3
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    also, you could easily do it with a shell script if you are on linux, or in a batch script in Windows.

  4. #4
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    Thanks for your response, EvBladeRunnervE. I'm now reading about the FTP protocol. However, how could this be done using a batch script ?

  5. #5
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    I havent used batch scripts in awhile, but basically what you are looking at is:

    1) mount a network drive
    2) copy the files over to that drive through basic dos calls

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    If you have administrator access on the remote pc:
    Code:
    copy "C:\Files\myfile.ext"  "\\remotepc\c$\program files\"
    I have a vbscript that copies a software patch to a remote pc, executes it and returns the result, if you are interested.

  7. #7
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    Thanks, Anonytmouse, but how could my program detect the name of remote computers ( remotepc ) and the name of the drive ( c$ ) ? Also, I would have thought that would be done without having admin access, as they are connected to a network, and files can be transferred to and from them.

  8. #8
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    you are then looking for enumerating your network resources, which I do not know if it is possible to do in batch, look it up on MSDN.

  9. #9
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> Thanks, Anonytmouse, but how could my program detect the name of remote computers <<

    With three computers, I would have thought you would just use a list.

    >> and the name of the drive ( c$ ) ? <<

    c$ is an admin share that is installed by default and points to "C:\". If you want to use another share, again, I would use a list.

    However, you can enumverate computers and shares using code and possibly with the "net view" command (try it). You can also do this with a vbscript.

    >> Also, I would have thought that would be done without having admin access, as they are connected to a network, and files can be transferred to and from them. <<

    As mentioned c$ is an admin share, if you have installed other shares, they may indeed be available to other users.

    Can you confirm that your network is Windows 2000/XP or are we talking 98 (everything above applies to 2000/XP only)?

  10. #10
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    Anonytmous, I was hoping to be able to learn how to find the name of remote computers, to be able to do this without having to have a list, as this would be useful later on, if I have access to larger networks.

    As for the admin share, the same goes, I'd like to detect these, if I don't have a list of them.

    As for the network, I am dealing with WinXP computers.


    Thanks for your help.

  11. #11
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    OK, enumerating network computers and shares 101:

    Replace "YourWorkgroup" with the name of your workgroup or domain and "remotepc" with the name of a computer you want to query.

    Using commands:
    Code:
    :: To list network computers.
    NET VIEW /DOMAIN:YourWorkgroup
    
    :: To list shares on a computer.
    NET VIEW \\remotepc
    Using C/C++ code:
    Use NetServerEnum() and NetShareEnum() or WNetEnumResource().

    Using vbscript:
    Code:
    '''' Enumerate computers in a workgroup or domain.
    
    Dim domain    'As IADsDomain, IADsContainer, IADs
    Dim computer  'As IADsComputer, IADs
    
    Set domain    = GetObject("WinNT://YourWorkgroup")
    domain.Filter = Array("Computer")
    
    For Each computer In domain 
    	strComputer = computer.Name
    	WScript.Echo strComputer
    Next 
    
    
    '''' Enumerate shares on a computer using ADSI.
    
    Dim fs       'As IADsFileService, IADsContainer, IADs
    Dim share    'As IADsFileShare, IADs
    
    strComputer = "remotepc"
    Set fs = GetObject("WinNT://" & strComputer & "/lanmanserver")
    
    For Each share In fs
    	Wscript.Echo share.Name   
    	WScript.Echo share.HostComputer
    	WScript.Echo share.Path
    Next
    
    
    '''' Enumerate shares on a computer using WMI.
    
    strComputer = "remotepc"
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    
    Set colShares = objWMIService.ExecQuery("Select * from Win32_Share")
    
    For each objShare in colShares
        Wscript.Echo "AllowMaximum: " & vbTab &  objShare.AllowMaximum
        Wscript.Echo "Caption: " & vbTab &  objShare.Caption
        Wscript.Echo "MaximumAllowed: " & vbTab &  objShare.MaximumAllowed
        Wscript.Echo "Name: " & vbTab &  objShare.Name
        Wscript.Echo "Path: " & vbTab &  objShare.Path
        Wscript.Echo "Type: " & vbTab &  objShare.Type
    Next
    
    
    MsgBox "End"
    To execute vbscript, place it in a text file with the extension ".vbs" and double click to run. Note that the WMI method of enumerating shares will return hidden shares but requires admin access to run. I don't think the ADSI method requires admin access(assuming you have one or more accessible shares) but I don't think it will return hidden shares.

    Useful ADSI link (for searchers): http://dev.coadmin.dk/Resources/ADSI...HTML/winnt.htm
    Last edited by anonytmouse; 04-13-2004 at 03:51 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3D Network Analysis Tool
    By durban in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 11-08-2005, 05:33 PM
  2. Need help with easy Network setup
    By the dead tree in forum Tech Board
    Replies: 9
    Last Post: 04-08-2005, 07:44 PM
  3. Mapping network drives
    By Morgan in forum Windows Programming
    Replies: 4
    Last Post: 07-19-2004, 04:07 AM
  4. network problems
    By lucy in forum Tech Board
    Replies: 6
    Last Post: 01-01-2003, 02:33 PM
  5. WinXP Network Connections pop-up
    By DavidP in forum Tech Board
    Replies: 1
    Last Post: 10-02-2002, 05:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21