i have a String that either be network address or could be host name
$example1 = '\\192.168.3.3\s$\blabla\blabla\bla.txt'
$example2 = '\\srv\s$\blabla\bla.txt'
Im trying to test connection to the servers so i need only the \*****\ part.
$example1 = 192.168.3.3., $example2 = srv
im trying to use the -Match operation but im getting errors, can anyone assist?
There is a quick solution:
$example1.split("\")[2]
Works for both IP address or host names.
Related
I have a point-to-site VPN connection configured on 30+ client machines and I just had to change the VPN gateway's address. Of course, that means I have to reconfigure all of the client machines. Rather than do it manually, I was hoping I could create some kind of program or script that I could run which would update things automatically. The only thing I need to change is the server address, everything else should stay the same.
I came across these PowerShell commands Get-VpnConnection and Set-VpnConnection. I can successfully retreive the created VPN connection using this command:
Get-VpnConnection MyConnectionName -AllUserConnection
So I tried using the Set variant:
Set-VpnConnection -Name MyConnectionName -ServerAddress NewServerAddress -AllUserConnection
But this simply returns and does nothing. No error, no effect. Checking the server address with rasphone shows that the old address is still being used.
I can also do this:
$connection = Get-VpnConnection MyConnectionName -AllUserConnection
$connection.ServerName = NewServerAddress
This also doesn't do anything, since I'm pretty sure I'm just updating a variable and not "committing" it.
So how can I update the server address? It doesn't even have to be PowerShell, that was just the best option I could find.
I ended up writing a .NET application using DotRas.
If anyone's interested, here's the code:
Public Const EntryName As String = "VPNEntryNAme"
Public Const NewAddress As String = "NewVPNAddress"
Private Sub B_Update_Click(sender As Object, e As EventArgs) Handles B_Update.Click
Using pbk As New RasPhoneBook()
pbk.Open(RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers))
Dim VPN = pbk.Entries.Where(Function(Entry) Entry.Name = EntryName).FirstOrDefault
If VPN Is Nothing Then
MsgBox("VPN not found!", MsgBoxStyle.Critical)
Exit Sub
End If
VPN.PhoneNumber = NewAddress
VPN.Update()
End Using
Dim cn = RasConnection.GetActiveConnections.Where(Function(c) c.EntryName = EntryName).FirstOrDefault
If cn IsNot Nothing Then
cn.HangUp()
End If
MsgBox("The VPN has now been successfully updated")
End Sub
On my side, everything worked fine when I use
Set-VpnConnection -Name MyConnectionName -ServerAddress = "x.x.x.x"
Maybe you can try to remove the old one and a new one
$Connection = Get-VpnConnection -Name MyConnectionName
Remove-VpnConnection -Name MyConnectionName -Force
$Connection.ServerAddress = "x.x.x.x"
$Connection | Add-VpnConnection
When ever we try to let google crawl our website we get several errors in sentry:
The value "213.55.176.155, 66.249.93.93" is not a valid IP address
or
The value "213.55.176.162, 66.102.9.18" is not a valid IP address.
The code error is coming from "$record = $reader->city($ip);"
$reader = new Reader('GeoLite2-City.mmdb');
$record = $reader->city($ip);
// $ip = $_SERVER['REMOTE_ADDR'];
$iso_code = $record->country->isoCode;
$timezone = $record->location->timeZone;
We think its a AddressNotFoundException because the IP is not valid in geolite2 DB of maxmind.
Does anyone now how to avoid this error?
It looks like your string contains multiple IPs, so try splitting them and looping?
Something like:
$ips = explode(', ', $ip)
foreach(...) {
...
}
I'm using Xamarin.mac. I need to get the fully qualified domain name of the local computer. On Windows this code works:
public string GetFQDN()
{
string domainName = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
string hostName = Dns.GetHostName();
string fqdn = "";
if (!hostName.Contains(domainName))
fqdn = hostName + "." + domainName;
else
fqdn = hostName;
return fqdn;
}
On a mac this code causes this error: System.NotSupportedException: This platform is not supported.
So, what is the equivalent in Xamarin.mac? Or just in Mono?
Just getting the computer name would be a good start.
To do this, you can pretty much do the same you'd do in C on a UNIX system, which is to retrieve the hostname with gethostname() and then use a DNS lookup to find the canonical network name for the host. Luckily, System.Net has ready-made calls for this. The following code should work on both OS X and Linux (in fact, on Linux it is more or less what hostname --fqdn does):
using System;
using System.Net;
class Program {
static void Main() {
// Step 1: Get the host name
var hostname = Dns.GetHostName();
// Step 2: Perform a DNS lookup.
// Note that the lookup is not guaranteed to succeed, especially
// if the system is misconfigured. On the other hand, if that
// happens, you probably can't connect to the host by name, anyway.
var hostinfo = Dns.GetHostEntry(hostname);
// Step 3: Retrieve the canonical name.
var fqdn = hostinfo.HostName;
Console.WriteLine("FQDN: {0}", fqdn);
}
}
Note that with a misconfigured DNS, the DNS lookup may fail, or you may get the rather useless "localhost.localdomain".
If you wish to emulate your original approach, you can use the following code to retrieve the domainname:
var domainname = new StringBuilder(256);
Mono.Unix.Native.Syscall.getdomainname(domainname,
(ulong) domainname.Capacity - 1);
You will need to add the Mono.Posix assembly to your build for this.
I have a Windows logon script running and am compiling a set of details that get logged when the user logons on. As this is a remote server, all logons are done via RDP. I need to get the IP address of the user who has logged on. I have used the following:
Function WAN_IP()
Set objxmlHTTP = CreateObject("Microsoft.XMLHTTP")
Call objxmlHTTP.open("get", "http://checkip.dyndns.org", False)
objxmlHTTP.Send()
strHTMLText = objxmlHTTP.ResponseText
Set objxmlHTTP = Nothing
If strHTMLText <> "" Then
varStart = InStr(1, strHTMLText, "Current IP Address:", vbTextCompare) + 19
If varStart Then varStop = InStr(varStart, strHTMLText, "</body>", vbTextCompare)
If varStart And varStop Then strIP = Mid(strHTMLText, varStart, varStop - varStart)
Else
strIP = "Unavailable"
End If
WAN_IP = Trim(strIP)
End Function
This, as expected, returns the external IP of the server itself and not the IP of the user who has connected.
Is anybody able to let me know how I get the IP of the user connected via RDP?
Following the response from #MarcB I used How to get the IP Address of the Remote Desktop Client? to get the idea on what to do.
I then found some example code here: http://pleasepressanykey.blogspot.com/2008/09/get-users-last-successful-and-failed.html
I have been trying to write a simple ftp client using c# in .NET 2.0 for 3 days now and am
missing something. I I create an ftpWebRequest object and set all its properies.
string uri = host + remoteFile;
System.Net.FtpWebRequest ftp = (FtpWebRequest)(FtpWebRequest.Create(uri));
ftp.Credentials = new System.Net.NetworkCredential(username, password);
ftp.KeepAlive = false;
ftp.UseBinary = true;
ftp.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
But when I go to get the stream, it fails...
System.IO.Stream strm = ftp.GetRequestStream();
Here is the error: "System.Net.WebException: The remote server returned an error: (501) Syntax error in parameters or arguments."
This method SHOULD return the stream I need to write to and many examples do exactly this. I'm not sure what I'm missing. My host looks like this: "ftp://myhostname/" and I've triple checked my credentials.
Please help!
may be ftp.UseBinary = true; is not supported by server?
You are missing the "/" after the host:
string uri = host + "/" + remoteFile;
and the remote file string should look like this: file.txt without any path.