///
/// Ref: How To Get IP Address Of A Machine
/// Ref: WMI or How to change my IP address
/// using System.Management;
///
public string getLocalIP()
{
string localIP = "";
string strHostName = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostByName (strHostName);
IPAddress [] addr = ipEntry.AddressList;
/* what if more than one instance exists? */
for (int i = 0; i < addr.Length; i++)
{
localIP = addr[i].ToString();
}
return localIP;
}
public bool setLocalIP(string newIP) {
try
{
ManagementBaseObject inPar = null;
ManagementBaseObject outPar = null;
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (!(bool) mo["IPEnabled"]) continue;
inPar = mo.GetMethodParameters("EnableStatic");
inPar["IPAddress"] = new string[] {newIP};
inPar["SubnetMask"] = new string[] {subnetMask};
outPar = mo.InvokeMethod("EnableStatic", inPar, null);
break;
}
this.currentIP = newIP;
return true;
}
catch (Exception e)
{
this.setErrMsg(e.Message + "\nsource: " + e.Source);
return false;
}
}
static void SwitchToDHCP()
{
ManagementBaseObject inPar = null;
ManagementBaseObject outPar = null;
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach( ManagementObject mo in moc )
{
if( ! (bool) mo["IPEnabled"] )
continue;
inPar = mo.GetMethodParameters("EnableDHCP");
outPar = mo.InvokeMethod( "EnableDHCP", inPar, null );
break;
}
}
static void SwitchToStatic()
{
string newIP;
string subnetMask = "255.255.255.0";
newIP = (curIP.Equals("192.168.168.209"))?"192.168.168.204":"192.168.168.209";
ManagementBaseObject inPar = null;
ManagementBaseObject outPar = null;
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach( ManagementObject mo in moc )
{
if( ! (bool) mo[ "IPEnabled" ] )
continue;
inPar = mo.GetMethodParameters( "EnableStatic" );
inPar["IPAddress"] = new string[] { newIP };
inPar["SubnetMask"] = new string[] { subnetMask };
outPar = mo.InvokeMethod( "EnableStatic", inPar, null );
break;
}
}
static void ReportIP()
{
Console.WriteLine( "****** Current IP addresses:" );
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach( ManagementObject mo in moc )
{
if( ! (bool) mo[ "IPEnabled" ] )
continue;
Console.WriteLine( "{0}\n SVC: '{1}' MAC: [{2}]", (string) mo["Caption"],
(string) mo["ServiceName"], (string) mo["MACAddress"] );
string[] addresses = (string[]) mo[ "IPAddress" ];
string[] subnets = (string[]) mo[ "IPSubnet" ];
Console.WriteLine( " Addresses :" );
foreach(string sad in addresses)
Console.WriteLine( "\t'{0}'", sad );
Console.WriteLine( " Subnets :" );
foreach(string sub in subnets )
Console.WriteLine( "\t'{0}'", sub );
curIP = addresses[0];
}
}
Showing posts with label Network. Show all posts
Showing posts with label Network. Show all posts
Monday, July 26, 2010
C# work with local IP address
Tuesday, July 20, 2010
Sams Teach Yourself TCP/IP in 24 Hours
Sams Teach Yourself TCP/IP in 24 Hours (4th Edition) - by Joe Casad, 2008, 456 pages. ISBN-10: 0672329964.
I caught this book in sight at Barns and Noble. It is a short book to read, to the point and clear on basic concepts. Short is good.
I caught this book in sight at Barns and Noble. It is a short book to read, to the point and clear on basic concepts. Short is good.
I. TCP/IP basics
II. TCP/IP Protocol system
2. Correspondence of TCP/IP model and OSI model.
TCP/IP OSI Relevant protocols
----------------------------------------------------------------------------------
Application layer A,P,S
Transport layer T TCP/UDP
Internet layer N IP, ARP, RARP, ICMP, router(RIP, OSPF etc.)
Network access layer D,P FTS, FDDI, PPP, 802.11, 802.3, 802.16
note: 802.3 - ethernet, 802.11 - wireless, 802.16 - winmax
3. Network access layer
- physical addressing.
- LAN - ethernet.
CSMA/CS (Carrier Sense Multiple Access with Collision Detect)
ethernet frame: preamble|dest addr|sr addr|length|data|FCS(CRC)
4. Internet layer
- IP, IP header
- IP addressing: class A(8/24), B(16/16), C(24/8), D, E
- ARP (Address Resolution Protocol)
- RARP (Reverse ARP)
- ICMP
- BGP (Border Gateway Protocol), RIP (Routing Information Protocol)
5. Subnetting & CIDR (Classless Inter-Domain Routing)
- subnet mask/host ID
- split and combine networks.
6. Transport layer
- TCP/UDP
- ports, sockets
- multiplexing, demultiplexing.
- TCP: stream, resequencing, flow control, precedence & security, graceful close.
7. Application layer
- use socket/port to communicate with transport layer.
- target of multiplexing/de-multiplexing
III. Networking with TCP/IP
8. Routing
- routing table
- IP forwarding
- Dynamic routing algorithm
- DV (Distance vector). e.g. RIP
- LS (Link state). e.g. OSPF (Open Shortest Path First)
LS is more popular than DV now.
- Complex network routing
1) core router - backbone network (GGP)
2) exterior router - on border of autonomous systems (EGP: e.g. BGP)
3) interior router - within autonomous system (IGP: OSPF/RIP)
- classless routing: CIDR.
- OSPF: implemented as routed on unix/linux, builds SPT (Shortest Path Tree)
10. Firewall
- DMZ (Demilitarized Zone)
- rules
- proxy service
- reverse proxy
11. Name resolution
- DNS (Domain Name Server)
IV. TCP/IP utilities.
V. TCP/IP and the internet
18. Email
- outgoing email: SMTP
- incoming email: POP3/IMAP
19. Streaming and casting
- stack:
RTP
UDP
Internet layer
Network Access layer
VI. Advanced topics
Thursday, December 10, 2009
Network tools
To find out what server (IIS/Apache etc.) a site is running:
http://uptime.netcraft.com/up/graph
or: http://whois.domaintools.com/thedomainname.com
Many tools for analyzing web stuff:
http://www.dnsstuff.com/tools/
http://uptime.netcraft.com/up/graph
or: http://whois.domaintools.com/thedomainname.com
Many tools for analyzing web stuff:
http://www.dnsstuff.com/tools/
Saturday, September 12, 2009
Subscribe to:
Posts (Atom)
Blog Archive
-
▼
2026
(36)
-
▼
June
(19)
- C10K to C10M: from thread-per-connection model to ...
- Benchmark server performance
- Application server for php, python, java, node.js,...
- Application server for C++, Go and Rust
- Nginx as reverse proxy and load balancer
- Infrastructure running: nginx, apache, php, python...
- Flow chart of nginx+apache+uvcorn infrastructure
- Flow chart of apache+uvcorn infrastructure
- Uvicorn and Gunicorn
- What's deadsnakes PPA
- What's the optional lsb-core package
- Codex known logging bug
- Daemonsize a service
- Train text to image model, to generate images of c...
- Train a model based on OpenAI API
- Open port 8080 for WebSocket
- Add websocket support on Bluehost Ubuntu VPS for D...
- Install Claude Code on ubuntu VPS of Bluehost
- Install PostgreSQL on Mac
-
▼
June
(19)