private extern static uint RasGetProjectionInfo( int hrasconn, // handle to a RAS connection RASPROJECTION rasprojection, // type of control protocol [In, Out] RASPPPIP lpprojection, // pointer to a structure that ref uint lpcb // size of projection structure );
public string GetIP(int lphrsaConn) { RASPPPIP structProjection = new RASPPPIP(); uint uiProjSize = (uint)structProjection.dwSize; try { uint errorCode = RasGetProjectionInfo(lphrsaConn, RASPROJECTION.RASP_PppIp, structProjection, ref uiProjSize); return(structProjection.szIpAddress); } catch { return(""); } }
public static string GetIP(string strEntryName) { RASCONN[] Rasconn = new RASCONN[1]; Rasconn[0].dwSize = Marshal.SizeOf(Rasconn[0]); RASCONNSTATUS structure = new RASCONNSTATUS(); int lpcb = 0; int lpcConnections = 0; structure.dwSize = Marshal.SizeOf(structure); int nErrorValue = RasEnumConnections(Rasconn, ref lpcb, ref lpcConnections); switch (nErrorValue) { case 0: break; case 0x25b: Rasconn = new RASCONN[lpcConnections]; lpcb = Rasconn[0].dwSize = Marshal.SizeOf(Rasconn[0]); nErrorValue = RasEnumConnections(Rasconn, ref lpcb, ref lpcConnections); break; //default: //ConnectNotify(this.GetErrorString(nErrorValue), 3); //return; } int lphrsaConn = 0; foreach (RASCONN rasconn in Rasconn.Where(rasconn => rasconn.szEntryName == strEntryName)) { if (rasconn.hrasconn != 0) { lphrsaConn = rasconn.hrasconn; } } if (lphrsaConn == 0) { return(""); } RASPPPIP structProjection = new RASPPPIP(); uint uiProjSize = (uint)structProjection.dwSize; try { uint errorCode = RasGetProjectionInfo(lphrsaConn, RASPROJECTION.RASP_PppIp, structProjection, ref uiProjSize); return(structProjection.szIpAddress); } catch { return(""); } }