我如何使用Regex获取有关IP到Location API的信息
这是API
http://ipinfodb.com/ip_query.php?ip=74.125.45.100
我需要获得国家名称,地区/州和城市.
我试过这个:
$ip = $_SERVER["REMOTE_ADDR"];
$contents = @file_get_contents('http://ipinfodb.com/ip_query.php?ip=' . $ip . '');
$pattern = "/<CountryName>(.*)<CountryName>/";
preg_match($pattern, $contents, $regex);
$regex = !empty($regex[1]) ? $regex[1] : "FAIL";
echo $regex;
Run Code Online (Sandbox Code Playgroud)
当我回复$ regex时,我总是得到失败怎么能解决这个问题
可能重复:
如何使用.net检测Windows 64位平台?
如何使用.NET 2.0检索操作系统体系结构(x86或x64)?
我还没有找到任何在Google上获得操作系统架构的好方法.我发现的是如何判断进程是32位还是64位.
如果无论如何都没有在.NET 2.0中找到,请告诉我.:)
好吧,我在使用DownloadDataAsync并将字节返回给我时遇到了问题.这是我正在使用的代码:
private void button1_Click(object sender, EventArgs e)
{
byte[] bytes;
using (WebClient client = new WebClient())
{
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
bytes = client.DownloadDataAsync(new Uri("http://example.net/file.exe"));
}
}
void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
label1.Text = Math.Round(bytesIn / 1000) + " / " + Math.Round(totalBytes / 1000);
progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
if (progressBar1.Value == 100)
{
MessageBox.Show("Download Completed");
button2.Enabled = true;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是"无法将类型'void'隐式转换为'byte []'"
无论如何我可以使这成为可能,并在完成下载后给我字节数?删除"bytes …
我正在努力让我的客户端通过下载字节并使用反射打开它来打开另一个程序.我目前在C#控制台应用程序上工作,但是当我尝试在Windows窗体应用程序上执行此操作时,我收到此错误.
"调用的目标引发了异常."
这是代码
using System;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text;
private void listBox1_DoubleClick(object sender, EventArgs e)
{
if (listBox1.SelectedItem.ToString() != null)
{
if (MessageBox.Show("Run " + listBox1.SelectedItem.ToString() + "?", "Run this program?", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
byte[] bytes;
using (WebClient client = new WebClient())
{
bytes = client.DownloadData(new Uri("http://example.net/program.exe"));
}
RunFromBytes(bytes);
}
}
}
private static void RunFromBytes(byte[] bytes)
{
Assembly exeAssembly = Assembly.Load(bytes);
exeAssembly.EntryPoint.Invoke(null, null);
}
Run Code Online (Sandbox Code Playgroud) 我如何从VB.net将其转换为C#.我尝试了在线转换器但是当我把它放在我的项目中时我遇到了错误.
Dim regexinfo As String = String.Empty
Dim p = "\[news\](?<info>.*?)\[/news\]"
Dim Matches = Regex.Matches(response, p, RegexOptions.IgnoreCase Or RegexOptions.Singleline)
If Matches IsNot Nothing AndAlso Matches.Count > 0 Then
For Each Match As Match In Matches
If Match.Groups("info").Success Then
regexinfo = (Match.Groups("info").Value)
End If
Next
End If
Run Code Online (Sandbox Code Playgroud) c# ×4
regex ×2
.net ×1
.net-2.0 ×1
64-bit ×1
api ×1
assemblies ×1
asynchronous ×1
byte ×1
download ×1
geoip ×1
php ×1
progress-bar ×1
reflection ×1
vb.net ×1
windows ×1
x86 ×1
xml ×1