?
Solved

set the IP of the PC

Posted on 2004-04-28
8
Medium Priority
?
176 Views
Last Modified: 2010-04-05
hi experts ,
i work with client/server socket and they work together but i have a littel problem so this problem can list in 2 points :
first how to set the IP of the PC (i choose it).
second how to get the server of network IP if my PC is a part of this network.
0
Comment
Question by:jimy7s
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
8 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 252 total points
ID: 10945114
The IP-address and the IP-Mask are  located in the registry :
the location is differrent for each OS (Win9X, NT4, NT5)

Example:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\NetTrans\0002

You will need to find the key where your info is stored....

Shane


procedure TForm1.SetTCPIP(IpAddress, IpMask:pchar);
var KeyHandle, SubKeyHandle:THandle;
    SubKeyName, NetworkDesc:array[0..255] of char;
    ValType, NetworkDescLength, SubKeyNameLength, index:dword;
    LastWriteTime:PFileTime;
begin
  index:=0;
  SubKeyNameLength:=255;
  RegOpenKeyEx(HKEY_LOCAL_MACHINE,
'System\CurrentControlSet\Services\Class\NetTrans', 0, KEY_ALL_ACCESS,
KeyHandle);
  while (RegEnumKeyEx(KeyHandle, index, SubKeyName, SubKeyNameLength, nil,
nil, nil, LastWriteTime)<>ERROR_NO_MORE_ITEMS) do
  begin
    RegOpenKeyEx(KeyHandle, SubKeyName, 0, KEY_ALL_ACCESS, SubKeyHandle);

    NetWorkDescLength:=255;
    RegQueryValueEx(SubKeyHandle, 'DriverDesc', nil, @ValType, @NetworkDesc,
@NetworkDescLength);
    if (NetworkDesc='TCP/IP') then break;

    inc(index);
    SubKeyNameLength:=255;
  end;
  if (NetworkDesc<>'TCP/IP') then
  begin
    messagebox(0,'TCP/IP protocol is not installed on your computer','',0);
    exit;
  end;
  NetWorkDescLength:=255;
  RegSetValueEx(SubKeyHandle, 'IPAddress', 0, REG_SZ, IpAddress, 15);
  RegSetValueEx(SubKeyHandle, 'IPMask', 0, REG_SZ, IpMask, 15);
end;


then call the procedure on a button click or so...

SetTCPIP('255.254.253.255', '255.255.255.255');//IP, Subnetmask...


Shane
0
 
LVL 12

Assisted Solution

by:Ivanov_G
Ivanov_G earned 248 total points
ID: 10946535
0
 

Author Comment

by:jimy7s
ID: 10955095
guys if i set IP by force did the Internet connection effecte
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10956716

   The same way it is affected if you change the IP address manually from Network Neighbourhood...
0
 

Author Comment

by:jimy7s
ID: 10965138
Thanks shaneholmes And Ivanov ;
bytheway shaneholmes if i use widows Xp what is the change ?
is the the code still as it was . Cause the error occur when i compiled this segment of code.
           and thanks for you both ;
                        jimmy
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question